語言

KeyGesture.Matches(Object, InputEventArgs) 方法

定義

判斷此輸入 KeyGesture 是否與指定 InputEventArgs 物件相關。

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

目標。

inputEventArgs
InputEventArgs

輸入事件資料用來比較這個手勢。

傳回

true 若事件資料符合此 KeyGesture;否則, false。

範例

以下範例說明如何測試 a KeyGesture 是否與 實例 InputEventArgs相關聯的輸入相符。 會建立一個KeyDown事件處理程序,透過 該KeyGesture方法將事件資料與 Matches 進行比較。

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 可以用來更具體地決定是否應該對特定元素呼叫指令。

適用於