MouseButtonState Enumeration
TOC
Collapse the table of content
Expand the table of content

MouseButtonState Enumeration

 

Specifies the possible states of a mouse button.

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

public enum MouseButtonState

Member nameDescription
Pressed

The button is pressed.

Released

The 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
Available since 3.0
Return to top
Show:
© 2016 Microsoft