MouseButton Enumeración

Definición

Define valores que especifican los botones en un dispositivo de mouse.Defines values that specify the buttons on a mouse device.

public enum class MouseButton
public enum MouseButton
type MouseButton = 
Public Enum MouseButton
Herencia
MouseButton

Campos

Left 0

Botón primario del mouse.The left mouse button.

Middle 1

Botón central del mouse.The middle mouse button.

Right 2

Botón secundario del mouse.The right mouse button.

XButton1 3

Primer botón de mouse extendido.The first extended mouse button.

XButton2 4

Segundo botón de mouse extendido.The second extended mouse button.

Ejemplos

En el ejemplo siguiente se crea un MouseDown controlador de eventos que utiliza la MouseButton enumeración para determinar el botón que se presionó.The following example creates a MouseDown event handler that uses the MouseButton enumeration to determine which button was pressed. Dependiendo del botón que se presionó, cambia el fondo del control que desencadenó el evento.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;
        }
    }
}
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

Se aplica a

Consulte también