如何检测鼠标是向左移动还是向右移动? [英] How can I detect if the mouse is being moved to the left or right?
本文介绍了如何检测鼠标是向左移动还是向右移动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试检测控件的左右鼠标移动 - 就像您可以使用 delta 进行向上/向下移动一样.有人能帮忙吗?谢谢.
如果 e.x >0 然后'向右移动msgbox("向右移动!")否则'向左移动msgbox("向左移动!")万一
解决方案
Private oldXY As Point = Point.EmptyPrivate Sub Form1_MouseMove(sender As Object,e As MouseEventArgs) 处理 Me.MouseMove如果 e.X oldXY.X 然后' ...万一旧XY.X = e.X旧XY.Y = e.Y结束子
您可能希望为 Point.Empty 添加测试,以免误报第一个鼠标移动.或者尝试将其初始化为 Cursor.Position
以
I am trying to detect the left and right mouse movements for a control - like you can use delta for up/down movement. Can anyone help with this? Thanks.
If e.x > 0 Then 'moved right
msgbox("Moved right!")
else 'moved left
msgbox("Moved left!")
End If
解决方案
Private oldXY As Point = Point.Empty
Private Sub Form1_MouseMove(sender As Object,
e As MouseEventArgs) Handles Me.MouseMove
If e.X < oldXY.X Then
' ....
ElseIf e.X > oldXY.X Then
' ...
End If
oldXY.X = e.X
oldXY.Y = e.Y
End Sub
You will likely want to add a test for Point.Empty so that you dont misreport the first mousemove. Or try to initialize it to Cursor.Position
to start with
这篇关于如何检测鼠标是向左移动还是向右移动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文