Welcome to MSDN Blogs Sign in | Join | Help

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?

 

Published Wednesday, February 26, 2003 11:03 PM by Addys
Filed under:

Comments

# re: Detecting mouse buttons in .NET

Wednesday, February 26, 2003 5:00 PM by Duncan Mackenzie
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.

# Santomania Detecting mouse buttons in NET | Outdoor Ceiling Fans

# Santomania Detecting mouse buttons in NET | Outdoor Ceiling Fans

New Comments to this post are disabled
 
Page view tracker