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 提供用于确定鼠标状态的其他属性和方法。

适用于

另请参阅