Expand Minimize

MouseButtonState Enumeration

Specifies the possible states of a mouse button.

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

'Declaration
Public Enumeration MouseButtonState
'Usage
Dim instance As MouseButtonState
<object property="enumerationMemberName" .../>

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

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

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.

.NET Framework

Supported in: 3.5, 3.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft