System.Windows.Forms.Control.KeyPress Event

Occurs when a key is pressed while the control has focus.

Syntax

public event KeyPressEventHandler KeyPress

Remarks

Key events occur in the following order:

[The 'ordered' type of list has not been implemented in the ECMA stylesheet.]

The Control.KeyPress event is not raised by noncharacter keys; however, the noncharacter keys do raise the Control.KeyDown and Control.KeyUp events.

Use the KeyPressEventArgs.KeyChar property to sample keystrokes at run time and to consume or modify a subset of common keystrokes.

To handle keyboard events only at the form level and not enable other controls to receive keyboard events, set the KeyPressEventArgs.Handled property in your form's Control.KeyPress event-handling method to true.

For more information about handling events, see Consuming Events.

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0