KeyEventHandler KeyEventHandler KeyEventHandler KeyEventHandler Delegate


代表將處理 KeyUpKeyDown 路由事件,以及相關的附加事件和預覽事件的方法。Represents the method that will handle the KeyUp and KeyDown routed events, as well as related attached and Preview events.

public delegate void KeyEventHandler(System::Object ^ sender, KeyEventArgs ^ e);
public delegate void KeyEventHandler(object sender, KeyEventArgs e);
type KeyEventHandler = delegate of obj * KeyEventArgs -> unit
Public Delegate Sub KeyEventHandler(sender As Object, e As KeyEventArgs)


Object Object Object Object

附加事件處理常式的物件。The object where the event handler is attached.

KeyEventArgs KeyEventArgs KeyEventArgs KeyEventArgs

事件資料。The event data.



下列範例會檢查與事件相關聯的金鑰是否Return索引鍵。The following example checks whether the key associated with the event is the Return key.

private void OnKeyDownHandler(object sender, KeyEventArgs e)
    if (e.Key == Key.Return)
        textBlock1.Text = "You Entered: " + textBox1.Text;
Private Sub OnKeyDownHandler(ByVal sender As Object, ByVal e As KeyEventArgs)
    If (e.Key = Key.Return) Then
        textBlock1.Text = "You Entered: " + textBox1.Text
    End If
End Sub


這個委派會使用下列的附加事件使用:This delegate is used with the following attached events:

這個委派也可搭配基底項目上的下列路由事件。This delegate is also used with the following routed events on base elements. 這些路由的事件轉送先前所列出的附加的事件,使其更容易存取中的一般項目模型WPFWPFThese routed events forward the previously listed attached events to make them more accessible to the general element model in WPFWPF.

附加的事件和基底的項目路由事件共用其事件資料,而事件反昇和通道路由事件的版本也會共用事件資料。The attached events and the base element routed events share their event data, and the bubbling and tunneling versions of the routed events also share event data. 傳送的事件路由,這可能會影響事件的處理的特性。This can affect the handled characteristics of the event as it travels the event route. 如需詳細資訊,請參閱 < 輸入概觀For details, see Input Overview.


GetMethodInfo(Delegate) GetMethodInfo(Delegate) GetMethodInfo(Delegate) GetMethodInfo(Delegate)

取得表示特定委派所代表之方法的物件。Gets an object that represents the method represented by the specified delegate.