ybchen的思路不错,但没必要用什么timer,在控件的MouseMove事件里利用SetCapture和ReleaseCapture造出一某MouseLeaveshijian事件就OK了。
看懂下面的例子你就什么都明白了:
Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
' 没有使用MouseLeave事件,当鼠标快速移动时,程序来不及响应
StatusBar1.Panels(1).Text = "This is Command1"
End Sub
Private Sub Command2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim MouseOver As Boolean
'判断当前鼠标位置是否在Command2上
MouseOver = (0 <= X) And (X <= Command2.Width) And (0 <= Y) And (Y <= Command2.Height)
If MouseOver Then
' MouseOver Event
' 假如鼠标在Command2上, 则利用SetCapture将每一个鼠标事件都传递给Command2
' 并在StatusBar1.Panels(1)上显示帮助信息
StatusBar1.Panels(1).Text = "This is Command2"
SetCapture Command2.hWnd
Else
' MouseLeave Event
' 假如鼠标不在Command2上, 则利用SetCapture释放鼠标捕捉
' 并清除在StatusBar1.Panels(1)上的帮助信息
StatusBar1.Panels(1).Text = ""
ReleaseCapture
End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
StatusBar1.Panels(1).Text = ""
End Sub
有么问题再问?