MouseButtonEventArgs.ButtonState プロパティ

定義

イベントに関連付けられているボタンの状態を取得します。

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

プロパティ値

ボタンの状態。

次の例では、イベントを処理するオブジェクトの色を変更するマウス ボタン イベント ハンドラーを作成します。 選択される色は、マウス ボタンが押されたか離されたかによって異なります。

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

注釈

クラスには Mouse 、マウスの状態を判断するための追加のプロパティとメソッドが用意されています。

適用対象

こちらもご覧ください