Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

MouseButtonState Enumeration

Specifies the possible states of a mouse button.

Namespace:  System.Windows.Input
Assembly:  PresentationCore (in PresentationCore.dll)

public enum MouseButtonState
<object property="enumerationMemberName" .../>

Member nameDescription
PressedThe button is pressed.
ReleasedThe button is released.

The MouseButtonState enumeration specifies constants which correlate to the state of a mouse button.

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");
    }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft