KeyEventHandler 代理人

定義

代表將處理 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)

參數

sender
Object

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

e
KeyEventArgs

事件資料。The event data.

繼承
KeyEventHandler

範例

下列範例會檢查與事件相關聯的索引鍵是否為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. 這些路由事件會轉送先前列出的附加事件, 讓中WPFWPF的一般元素模型更容易存取。These 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)

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

適用於

另請參閱