How to detect if mouse is pressed

北战南征 提交于 2020-01-15 08:32:07

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!