(VB)怎么判断光标处在某个text控件上?
来源:百度知道 编辑:UC知道 时间:2024/06/05 01:06:48
(VB)怎么判断光标处在某个text控件上?
用Form的ActiveControl 属性,如下面代码:
Private Sub Form_DblClick()
If Form1.ActiveControl Is Text1 Then
Text2.SetFocus
ElseIf Form1.ActiveControl Is Text2 Then
Text1.SetFocus
End If
End Sub
text.setfocus()
Private Sub Form_DblClick()
Dim x As TextBox
For Each x In Form1
If Form1.ActiveControl Is x Then
x.SetFocus
End If
Next
End Sub
使用文本框的GotFocus事件
假设你的窗体上有两个文本框 名字为 Text1 和 Text2
下面的代码就可以判断
Private Sub Text1_GotFocus()
MsgBox "光标在Text1"
End Sub
Private Sub Text2_GotFocus()
MsgBox "光标在Text2"
End Sub