MouseButtonEventArgs.ButtonState MouseButtonEventArgs.ButtonState MouseButtonEventArgs.ButtonState MouseButtonEventArgs.ButtonState Property

Definition

Gets the state of the button associated with the event.

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

Property Value

Examples

The following example creates a mouse button event handler that changes the color of the object that handles the event. The color that is chosen depends on whether the mouse button was pressed or released.

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

Remarks

The Mouse class provides additional properties and methods for determining the state of the mouse.

Applies to

See also