vb6.0 鼠标离开事件
vb6.0 中没有鼠标离开事件,经常要在几个控件上使用mouseMove事件,才能起到鼠标离开事件。 这个是从网上找来的程序。首先要求的是控件必须有hWnd属性
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)
Dim MouseOver As Boolean
'判断当前鼠标位置是否在Object1上
MouseOver = (0 <= X) And (X <= Command1.Width) And (0 <= Y) And (Y <= Command1.Height)
If MouseOver Then
' MouseOver Event
' 假如鼠标在Object1上, 则利用SetCapture将每一个鼠标事件都传递给Object1
Me.Caption = "0"
SetCapture Command1.hWnd
Else
' MouseLeave Event
' 假如鼠标不在Object1上, 则利用SetCapture释放鼠标捕捉
Me.Caption = "1"
ReleaseCapture
End If
End Sub
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim MouseOver As Boolean
'判断当前鼠标位置是否在Object1上
MouseOver = (0 <= X) And (X <= Command1.Width) And (0 <= Y) And (Y <= Command1.Height)
If MouseOver Then
' MouseOver Event
' 假如鼠标在Object1上, 则利用SetCapture将每一个鼠标事件都传递给Object1
Me.Caption = "0"
SetCapture Command1.hWnd
Else
' MouseLeave Event
' 假如鼠标不在Object1上, 则利用SetCapture释放鼠标捕捉
Me.Caption = "1"
ReleaseCapture
End If
End Sub
|
暂时没有评论
发表评论 - 不要忘了输入验证码哦! |