简体   繁体   English

检查鼠标按钮是否被按下并按住

[英]Check whether a mouse button is pressed and held pressed

I have a project with a lot of mouse events.我有一个包含很多鼠标事件的项目。

I need to do different things depending whether the mouse left button is clicked or it is pressed and kept pressed.我需要根据是单击鼠标左键还是按下鼠标左键并保持按下来做不同的事情。 The same for the right mouse button.鼠标右键也一样。

I was unable to find any example that shows how to check a mouse button held pressed.我找不到任何显示如何检查按住鼠标按钮的示例。

if (e.Button == MouseButtons.Right)
{
     // Shows that the right mouse was pressed. 
     // It does not show whether it has also been kept pressed.
}

In the same way I check which mouse button is pressed I need a Boolean that shows that it is also kept pressed.以同样的方式,我检查按下了哪个鼠标按钮,我需要一个 Boolean 来显示它也被按下。 I have no idea how to go about solving this.我不知道如何解决这个问题。

Any help would be much appreciated.任何帮助将非常感激。

Thank you in advance.先感谢您。

I'm going to go out on a limb and assume that what you actually want is to know whether the left mouse button is depressed when something else happens, which seems the most likely to me.我将四肢走 go 并假设您真正想要的是知道发生其他事情时是否按下鼠标左键,这对我来说似乎最有可能。 In that case, you can do something like this:在这种情况下,您可以执行以下操作:

private void textBox1_TextChanged(object sender, EventArgs e)
{
    if (Control.MouseButtons == MouseButtons.Left)
    {
        // The left mouse button and ONLY that button is depressed.
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM