MouseButtonEventArgs.ButtonState Właściwość

Definicja

Pobiera stan przycisku skojarzonego ze zdarzeniem.

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

Wartość właściwości

Stan, w który znajduje się przycisk.

Przykłady

Poniższy przykład tworzy procedurę obsługi zdarzeń przycisku myszy, która zmienia kolor obiektu obsługującego zdarzenie. Wybrany kolor zależy od tego, czy przycisk myszy został naciśnięty, czy zwolniony.

private void MouseButtonEventHandler(object sender, MouseButtonEventArgs e)
{
    if (e.ButtonState == MouseButtonState.Pressed)
    {
        this.Background = Brushes.BurlyWood;
    }

    if (e.ButtonState == MouseButtonState.Released)
    {
        this.Background = Brushes.Ivory;
    }
}
Private Sub MouseButtonEventHandler(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
    If e.ButtonState = MouseButtonState.Pressed Then
        Me.Background = Brushes.BurlyWood
    End If

    If e.ButtonState = MouseButtonState.Released Then
        Me.Background = Brushes.Ivory
    End If
End Sub

Uwagi

Klasa Mouse udostępnia dodatkowe właściwości i metody określania stanu myszy.

Dotyczy

Zobacz też