vb.net 如何检测鼠标是否被按下

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20015791/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 15:51:14  来源:igfitidea点击:

How to detect if mouse is pressed

vb.netmouse

提问by

In VB.NET how do you detect if a mouse button is currently pressed?

在 VB.NET 中,如何检测当前是否按下了鼠标按钮?

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.

我想知道是否有比创建单独的鼠标向上和鼠标向下事件更好的方法。

回答by ohgodnotanotherone

Assuming that you are using Windows Forms:

假设您使用的是 Windows 窗体:

MouseButtons.HasFlag(MouseButtons.Right)

MouseButtons.HasFlag(MouseButtons.Right)

This will return Trueif the right mouse button is currently being pressed.

True如果当前正在按下鼠标右键,这将返回。

For any mouse button being pressed you could do something like this:

对于按下的任何鼠标按钮,您可以执行以下操作:

If Not MouseButtons.HasFlags(MouseButtons.None) Then '...

回答by Alfonso Rubalcava

If System.Windows.Input.Mouse.LeftButton.HasFlag(MouseButtonState.Pressed) OR System.Windows.Input.Mouse.RigthButton.HasFlag(MouseButtonState.Pressed) Then
       Your Code
End If

回答by K3rnel31

on the mouseclickevent add this

mouseclick事件中添加这个

        If Not (e.Button = Windows.Forms.MouseButtons.Left And e.Button = Windows.Forms.MouseButtons.Right) Then MsgBox("mouse is up")