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 (3)

  1. private void panel1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)



    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.

Skip to main content