System.Windows.Forms.Control.KeyDown Event

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

Syntax

public event KeyEventHandler KeyDown

Remarks

Key events occur in the following order:

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

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. Certain keys, such as the TAB, RETURN, ESC, and arrow keys are handled by controls automatically. To have these keys raise the Control.KeyDown event, you must override the Control.IsInputKey(Keys) method in each control on your form. The code for the override of the Control.IsInputKey(Keys) would need to determine if one of the special keys is pressed and return a value of true. Instead of overriding the Control.IsInputKey(Keys) method, you can handle the Control.PreviewKeyDown event and set the PreviewKeyDownEventArgs.IsInputKey property to true. For a code example, see the Control.PreviewKeyDown event.

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