Compartilhar via


Detecting mouse buttons in .NET

This is embarrassingly stupid - I'll be realistic and assume that I'm the stupid one here:

When developing with Winforms, most events allow checking the state of the mousebuttons using the MouseButtons enum.  However I can't seem to catch combinations - for example, if the user presser both the right and middle button at once, I want to handle it differently than a standard right-click.  Why? Don't ask - its a long story.

Anyhow, the enum does not include combinatations, and even trying various ANDs I haven't been able to detect this. Ideas anyone?

Comments

  • Anonymous
    February 26, 2003
    private void panel1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    Debug.WriteLine(System.Windows.Forms.Control.MouseButtons);
    Debug.WriteLine("MouseDown: " + e.Button.ToString());
    }

    The trick is to check the static MouseButtons property, e.Button will only contain the mouse button that caused the event so it will only ever contain a single button at a time.
  • Anonymous
    May 30, 2009
    PingBack from http://outdoorceilingfansite.info/story.php?id=2211
  • Anonymous
    May 31, 2009
    PingBack from http://outdoorceilingfansite.info/story.php?id=19847