MouseButtonEventArgs.ChangedButton Eigenschaft

Definition

Ruft die Taste ab, die mit dem Ereignis verknüpft ist.Gets the button associated with the event.

public:
 property System::Windows::Input::MouseButton ChangedButton { System::Windows::Input::MouseButton get(); };
public System.Windows.Input.MouseButton ChangedButton { get; }
member this.ChangedButton : System.Windows.Input.MouseButton
Public ReadOnly Property ChangedButton As MouseButton

Eigenschaftswert

MouseButton

Die Taste, die gedrückt wurde.The button which was pressed.

Beispiele

Im folgenden Beispiel wird ein Mauszeiger-Ereignishandler erstellt, der die Farbe eines Objekts abhängig von der Maus Taste ändert, die gedrückt wurde.The following example creates a mouse button event handler that changes the color of an object depending on the mouse button which was pressed. Die- ChangedButton Eigenschaft wird geprüft, um zu bestimmen, welche Schaltfläche gedrückt wurde.The ChangedButton property is checked to determine which button was pressed.

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

Hinweise

Die Mouse -Klasse stellt zusätzliche Eigenschaften und Methoden zum Bestimmen des Status der Maus bereit.The Mouse class provides additional properties and methods for determining the state of the mouse.

Gilt für:

Weitere Informationen