怎么样知道鼠标离开控件了

来源:百度知道 编辑:UC知道 时间:2024/06/04 03:09:12
求一代码:
1.当鼠标离开控件后.就msgbox
2.为什么输入text1.setfocus不能用啊.运行时出错.那要怎么写,如窗口一运行就把光标放到text1去.除了在控件属性里面修改tobindex顺序.

第一问题

你在form里面建一个mouse move 事件
然后在里面获取鼠标坐标X,Y
再用这个坐标与控件的坐标比较

以下以label1为例:

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If x < Label1.Left Then
MsgBox "已离开"
ElseIf y > Label1.Top Then
MsgBox "已离开"
ElseIf y < Label1.Top + Label1.Height Then
MsgBox "已离开"
ElseIf x > Label1.Left + Label1.Width Then
MsgBox "已离开"
End If

第二问题

Private Sub Form_Activate()
Text1.SetFocus
End Sub

第二问题

Private Sub Form_Activate()
Text1.SetFocus
End Sub

我的应该是最符合你的要求的....
(1)
Dim con As Boolean

Private Sub Form_Load()
con = False
End Sub

Private Sub form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If con Then MsgBox "aa": con = False
End Sub
Private Sub Label1_MouseMove(B