This documentation is archived and is not being maintained.
MouseButtonState Enumeration
Visual Studio 2008
Specifies the possible states of a mouse button.
Assembly: PresentationCore (in PresentationCore.dll)
The following example shows a mouse event handler that determines which buttons are currently pressed by checking the button state of each mouse button.
private void MouseDownHandler(object sender, MouseEventArgs e) { if (e.RightButton == MouseButtonState.Pressed) { MessageBox.Show("The Right Mouse Button is pressed"); } if (e.LeftButton == MouseButtonState.Pressed) { MessageBox.Show("The Left Mouse Button is pressed"); } if (e.MiddleButton == MouseButtonState.Pressed) { MessageBox.Show("The Middle Mouse Button is pressed"); } if (e.XButton1 == MouseButtonState.Pressed) { MessageBox.Show("The XButton1 Mouse Button is pressed"); } if (e.XButton2 == MouseButtonState.Pressed) { MessageBox.Show("The XButton2 Mouse Button is pressed"); } }
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: