问题
In VB.NET how do you detect if a mouse button is currently pressed?
ex:
If Mouse.Button1.IsHeldDown Then
...
End If
I would like to know if there is a better way than creating seperate mouse up and mouse down events.
回答1:
Assuming that you are using Windows Forms:
MouseButtons.HasFlag(MouseButtons.Right)
This will return True
if the right mouse button is currently being pressed.
For any mouse button being pressed you could do something like this:
If Not MouseButtons.HasFlags(MouseButtons.None) Then '...
回答2:
If System.Windows.Input.Mouse.LeftButton.HasFlag(MouseButtonState.Pressed) OR System.Windows.Input.Mouse.RigthButton.HasFlag(MouseButtonState.Pressed) Then
Your Code
End If
回答3:
on the mouseclick
event add this
If Not (e.Button = Windows.Forms.MouseButtons.Left And e.Button = Windows.Forms.MouseButtons.Right) Then MsgBox("mouse is up")
来源:https://stackoverflow.com/questions/20015791/how-to-detect-if-mouse-is-pressed