Breyta

Deila með


KeyEventHandler Delegate

Definition

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)

Parameters

sender
Object

The object where the event handler is attached.

e
KeyEventArgs

The event data.

Examples

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

Remarks

This delegate is used with the following attached events:

This delegate is also used with the following routed events on base elements. These routed events forward the previously listed attached events to make them more accessible to the general element model in WPF.

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.

Extension Methods

GetMethodInfo(Delegate)

Gets an object that represents the method represented by the specified delegate.

Applies to

See also