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 Enumeration 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 Sub MouseButtonDownHandler(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
    Dim src As Control = TryCast(e.Source, Control)

    If src IsNot Nothing Then
        Select Case e.ChangedButton
            Case MouseButton.Left
                src.Background = Brushes.Green
            Case MouseButton.Middle
                src.Background = Brushes.Red
            Case MouseButton.Right
                src.Background = Brushes.Yellow
            Case MouseButton.XButton1
                src.Background = Brushes.Brown
            Case MouseButton.XButton2
                src.Background = Brushes.Purple
            Case Else
        End Select
    End If
End Sub

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