KeyGesture.Matches(Object, InputEventArgs) Method
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.
Determines whether this KeyGesture matches the input associated with the specified InputEventArgs object.
public:
override bool Matches(System::Object ^ targetElement, System::Windows::Input::InputEventArgs ^ inputEventArgs);
public override bool Matches(object targetElement, System.Windows.Input.InputEventArgs inputEventArgs);
override this.Matches : obj * System.Windows.Input.InputEventArgs -> bool
Public Overrides Function Matches (targetElement As Object, inputEventArgs As InputEventArgs) As Boolean
- targetElement
- Object
The target.
- inputEventArgs
- InputEventArgs
The input event data to compare this gesture to.
true
if the event data matches this KeyGesture; otherwise, false
.
The following example shows how to test whether a KeyGesture matches the input associated with an instance of an InputEventArgs. A KeyDown event handler is created that compares the event data with the KeyGesture by using the Matches method.
private void OnKeyDown(object sender, KeyEventArgs e)
{
KeyGesture keyGesture = new KeyGesture(Key.B, ModifierKeys.Control);
if(keyGesture.Matches(null, e))
{
MessageBox.Show("Trapped Key Gesture");
}
}
Private Overloads Sub OnKeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
Dim keyGesture As New KeyGesture(Key.B, ModifierKeys.Control)
If keyGesture.Matches(Nothing, e) Then
MessageBox.Show("Trapped Key Gesture")
End If
End Sub
targetElement
can be used to make a more specific decision on whether a command should be invoked on a specific element.
Produkt | Versioner |
---|---|
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9, 10 |
Feedback om .NET
.NET är ett öppen källkod projekt. Välj en länk för att ge feedback: