MouseButtonEventArgs.ChangedButton プロパティ

定義

イベントに関連付けられているボタンを取得します。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

プロパティ値

押されたボタン。The button which was pressed.

次の例では、マウスボタンのイベントハンドラーを作成し、押されたマウスボタンに応じてオブジェクトの色を変更します。The following example creates a mouse button event handler that changes the color of an object depending on the mouse button which was pressed. プロパティChangedButtonは、どのボタンが押されたかを判断するためにチェックされます。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

注釈

クラスMouseには、マウスの状態を判断するための追加のプロパティとメソッドが用意されています。The Mouse class provides additional properties and methods for determining the state of the mouse.

適用対象

こちらもご覧ください