请问如何判断出鼠标从一个“命令按钮”上移开?

woookaooo 2003-05-17 05:39:37
请问如何判断出鼠标从一个“命令按钮”上移开?
...全文
5 点赞 收藏 8
写回复
8 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
danielinbiti 2003-05-17
用这个吧。
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 MouseEnter As Boolean
MouseEnter = (0 <= X) And (X <= Command1.Width) And (0 <= Y) And (Y <= Command1.Height)
If MouseEnter Then
SetCapture Command1.hwnd
Text1.Text = "Mouse in picture!"
Else
Text1.Text = "Mouse out!"
ReleaseCapture
End If
End Sub
回复
lee_j 2003-05-17
最好的办法就是用api捕捉 WM_MOUSELEAVE 消息
回复
woookaooo 2003-05-17
TO 天才的我:方法的确很妙,但是似乎不太灵敏:如果两个按钮相隔很近,鼠标移动快,就不很灵敏有时不能正确判断出。有解决的办法吗?谢谢!
回复
ywpg 2003-05-17
up

楼上的妙
回复
TimLee✿ 2003-05-17
最简单的方法~给Commandbutton旁边的控件加上Mousemove事件
回复
meil 2003-05-17
Dim i As Integer
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

i = 1

End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

If i = 1 Then
If Not (X > Command1.Left And X < Command1.Left + Command1.Width And _
Y > Command1.Top And Y < Command1.Top + Command1.Height) Then
MsgBox "鼠标已离开当前按钮!"
i = 0
End If
End If

End Sub
回复
meil 2003-05-17
Dim i As Integer
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

i = 1

End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

If i = 1 Then
If Not (X > Command1.Left And X < Command1.Left + Command1.Width And _
Y > Command1.Top And Y < Command1.Top + Command1.Height) Then
MsgBox "ds"
i = 0
End If
End If

End Sub
回复
danielinbiti 2003-05-17
Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Declare Function ReleaseCapture Lib "user32" () As Long
回复
相关推荐
发帖
VB基础类
创建于2007-09-28

7493

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2003-05-17 05:39
社区公告
暂无公告