System.Windows.Forms.Control.PreviewKeyDown Event

Occurs before the Control.KeyDown event when a key is pressed while focus is on this control.

Syntax

public event PreviewKeyDownEventHandler PreviewKeyDown

Remarks

Some key presses, such as the TAB, RETURN, ESC, and arrow keys, are typically ignored by some controls because they are not considered input key presses. For example, by default, a System.Windows.Controls.Button control ignores the arrow keys. Pressing the arrow keys typically causes the focus to move to the previous or next control. The arrow keys are considered navigation keys and pressing these keys typically do not raise the Control.KeyDown event for a System.Windows.Controls.Button. However, pressing the arrow keys for a System.Windows.Controls.Button does raise the Control.PreviewKeyDown event. By handling the Control.PreviewKeyDown event for a System.Windows.Controls.Button and setting the PreviewKeyDownEventArgs.IsInputKey property to true, you can raise the Control.KeyDown event when the arrow keys are pressed. However, if you handle the arrow keys, the focus will no longer move to the previous or next control.

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: 2.0.0.0