Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

MouseButton Enumeration

 

Defines values that specify the buttons on a mouse device.

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

public enum MouseButton

Member nameDescription
Left

The left mouse button.

Middle

The middle mouse button.

Right

The right mouse button.

XButton1

The first extended mouse button.

XButton2

The second extended mouse button.

The following example creates a MouseDown event handler that uses the MouseButton enumeration to determine which button was pressed. Depending on which button was pressed, the background of the control that fired the event is changed.

private void MouseButtonDownHandler(object sender, MouseButtonEventArgs e)
{
    Control src = e.Source as Control;

    if (src != null)
    {
        switch (e.ChangedButton)
        {
            case MouseButton.Left:
                src.Background = Brushes.Green;
                break;
            case MouseButton.Middle:
                src.Background = Brushes.Red;
                break;
            case MouseButton.Right:
                src.Background = Brushes.Yellow;
                break;
            case MouseButton.XButton1:
                src.Background = Brushes.Brown;
                break;
            case MouseButton.XButton2:
                src.Background = Brushes.Purple;
                break;
            default:
                break;
        }
    }
}

.NET Framework
Available since 3.0
Return to top
Show:
© 2016 Microsoft