MouseButton 列挙型

定義

マウス デバイスのボタンを指定する値を定義します。Defines values that specify the buttons on a mouse device.

public enum class MouseButton
public enum MouseButton
type MouseButton = 
Public Enum MouseButton
継承
MouseButton

フィールド

Left 0

マウスの左ボタンThe left mouse button.

Middle 1

マウスの中央ボタンThe middle mouse button.

Right 2

マウスの右ボタンThe right mouse button.

XButton1 3

マウスの第 1 拡張ボタン。The first extended mouse button.

XButton2 4

マウスの第 2 拡張ボタン。The second extended mouse button.

次の例ではMouseDown 、列挙体を使用MouseButtonして、どのボタンが押されたかを判断するイベントハンドラーを作成します。The following example creates a MouseDown event handler that uses the MouseButton enumeration to determine which button was pressed. 押されたボタンに応じて、イベントを発生させたコントロールの背景が変更されます。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

適用対象

こちらもご覧ください