Private Declare Function GetActiveWindow Lib "user32.dll" () As Long
可以设置一个模块级变量或用tag属性来标志是哪个文本框获得焦点:Private Sub Text1_LostFocus() Me.Tag = "Text1" End Sub Private Sub Text2_LostFocus() Me.Tag = "Text2" End Sub Private Sub Command1_Click() If Me.Tag = "Text1" Then MsgBox "Text1获得光标!" If Me.Tag = "Text2" Then MsgBox "Text2获得光标!" End Sub
如果text不多的话可以这样 Private Sub Command1_Click() Select Case x Case 1 Text1.Text = "光标在这里text1" Case 2 Text2.Text = "光标在这里text2" Case 3 Text3.Text = "光标在这里text3" End Select End Sub Private Sub Text1_GotFocus() x = 1 End SubPrivate Sub Text2_GotFocus() x = 2 End SubPrivate Sub Text3_GotFocus() x = 3 End Sub
Me.Tag = "Text1"
End Sub
Private Sub Text2_LostFocus()
Me.Tag = "Text2"
End Sub
Private Sub Command1_Click()
If Me.Tag = "Text1" Then MsgBox "Text1获得光标!"
If Me.Tag = "Text2" Then MsgBox "Text2获得光标!"
End Sub
Private Sub Command1_Click()
Select Case x
Case 1
Text1.Text = "光标在这里text1"
Case 2
Text2.Text = "光标在这里text2"
Case 3
Text3.Text = "光标在这里text3"
End Select
End Sub
Private Sub Text1_GotFocus()
x = 1
End SubPrivate Sub Text2_GotFocus()
x = 2
End SubPrivate Sub Text3_GotFocus()
x = 3
End Sub