Check whether a mouse button is pressed and held pressed

Viewed 50

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. I have no idea how to go about solving this.

Any help would be much appreciated.

Thank you in advance.

1 Answers

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. 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.
    }
}
Related