Property | Description |
---|---|
Alt | Gets a value indicating whether the ALT key was pressed. |
Control | Gets a value indicating whether the CTRL key was pressed. |
Handled | Gets or sets a value indicating whether the event was handled. |
KeyCode | Gets the keyboard code for a KeyDown or KeyUp event. |
KeyData | Gets the key data for a KeyDown or KeyUp event. |
KeyValue | Gets the keyboard value for a KeyDown or KeyUp event. |
Modifiers | Gets the modifier flags for a KeyDown or KeyUp event. This indicates which combination of modifier keys (CTRL, SHIFT, and ALT) were pressed. |
Shift | Gets a value indicating whether the SHIFT key was pressed. |
Control.KeyDown:
Occurs when a key is pressed while the control has focus.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Remarks
Key events occur in the following order:
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 KeyPress event-handling method to true. Certain keys, such as the TAB, RETURN, ESCAPE, and arrow keys are handled by controls automatically. To have these keys raise the KeyDown event, you must override the IsInputKey method in each control on your form. The code for the override of the IsInputKey would need to determine if one of the special keys is pressed and return a value of true.
For more information about handling events, see Consuming Events.
The following code example uses the KeyDown event to determine the type of character entered into the control.
Gets the modifier flags for a KeyDown or KeyUp event. This indicates which combination of modifier keys (CTRL, SHIFT, and ALT) were pressed.
[C#]
public Keys Modifiers {get;}
Property Value
A Keys value representing one or more modifier flags.
Remarks
To determine whether a specific modifier key was pressed, use the Control, Shift, and Alt properties. Modifier flags can be combined with bitwise OR.
Example