MouseButtonEventArgs.ChangedButton Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
Property Value
The button which was pressed.
Examples
The following example creates a mouse button event handler that changes the color of an object depending on the mouse button which was pressed. 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
Remarks
The Mouse class provides additional properties and methods for determining the state of the mouse.
Applies to
See also
التعاون معنا على GitHub
يمكن العثور على مصدر هذا المحتوى على GitHub حيث يمكنك أيضاً إضافة مشاكل وطلبات سحب ومراجعتها. للحصول على معلومات إضافية، اطلع على دليل المساهم لدينا.