形式GotFocus事件似乎并不火 [英] Forms GotFocus event does not seem to fire

查看:115
本文介绍了形式GotFocus事件似乎并不火的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图调用的事件当用户焦点返回到访问应用程序时的具体形式是开放的。下面的事件似乎并没有火起来的。

I'm trying to call an event when the user returns focus to the Access application when a specific form is open. The following event doesn't seem to fire up at all.

Private Sub Form_GotFocus()
    Call crtListDirectory
End Sub 

有没有任何机构有任何想法,我怎么可能会引发该事件的发生,以及何时/如何在Form_GotFocus事件实际被触发。

Does any body have any ideas as to how I could trigger this event to happen, and when/how does the Form_GotFocus event actually get triggered.

在此先感谢您的帮助

诺埃尔

推荐答案

访问帮助:

一个表单可以获取焦点只有当所有   在窗体上可见的控件   禁用,或者没有管制   形式。

A form can get the focus only if all visible controls on a form are disabled, or there are no controls on the form.

您可能会想尝试激活。

编辑回复评论

做你似乎想我可以看到的唯一方法是使用的API,这是有点乱。为了证明这一点,你需要与两个控件Text0和文本形式(这些都是默认的名称)。设置计时器的时间间隔,以合适的东西,比如说2000,并使用定时器事件为:

The only way I can see of doing what you seem to want is with APIs, which is somewhat messy. To demonstrate this you will need a form with two controls Text0 and Text2 (these are the default names). Set the Timer Interval to something suitable, say 2000, and the Timer Event to:

Private Sub Form_Timer()
Dim lngWin As Long
Dim s As String

    'This is just a counter to show that the code is running
    Me.Text2 = Nz(Me.Text2, 0) + 1

    'API
    lngWin = GetActiveWindow()
    s = GetWinName(lngWin)

    If s = "Microsoft Access" Then
        If Me.Text0 = "Lost Focus" Then
            Me.Text0 = "Focus returned"
        End If
    Else
        Me.Text0 = "Lost Focus"
    End If

End Sub

您现在需要的模块:

Option Compare Database

Declare Function GetActiveWindow Lib "user32" () As Integer
Declare Function GetWindowText Lib "user32.dll" Alias _
"GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As _
String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias _
"GetWindowTextLengthA" (ByVal hwnd As Long) As Long

Function GetWinName(hw As Long)
    Dim lngText As Long ' receives length of text of title bar
    Dim strWinName As String ' receives the text of the title bar
    Dim lngWinText As Long ' receives the length of the returned string

    lngText = GetWindowTextLength(hw)
    strWinName = Space(lngText + 1)
    lngWinText = GetWindowText(hw, strWinName, lngText + 1)
    strWinName = Left(strWinName, lngWinText)
    GetWinName = strWinName
End Function

这是非常,非常粗糙的,但它给大家介绍的东西乱。

This is all very, very rough, but it gives you something to mess about with.

这篇关于形式GotFocus事件似乎并不火的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆