VB 控件焦点!!
来源:百度知道 编辑:UC知道 时间:2024/05/12 20:44:44
我想要 获得 控件的焦点!!
如果Text 文本框上有焦点 返回 True
如果文本框没有 焦点 返回 False
如果Text 文本框上有焦点 返回 True
如果文本框没有 焦点 返回 False
用一个全局变量r 通过它来返回值
Dim r As Boolean
Private Sub Text1_GotFocus()
r = True
End Sub
Private Sub Text1_LostFocus()
r = False
End Sub
这样 你就可以在其他地方使用 If r=True Then...
If r=False Then... 来实现你想要的效果了
text1.setfcous
form_load事件不支持text1.setfcous
可以在click事件里使用!
用个API吧~在工程里面加时钟控件timer1,timer1的interval属性设置为1.
Private Declare Function GetFocus Lib "user32" () As Long
Private Sub Timer1_Timer()
If Text1.hWnd = GetFocus Then
Text1.Text = True
Else
Text1.Text = False
End If
End Sub