KeyPreview Property

Object List Next Object

Defined By:
Form

Description:

Determines which events are invoked first, form keyboard events or control keyboard events. KeyDown, KeyUp, and KeyPress are the keyboard events.

Settings:


Setting Description


True The form receives keyboard events first, the active control receives keyboard events second.

False (Default) Only the active control receives keyboard events.

Details:

You can use KeyPreview to set up a keyboard handling procedure at the form level. This is useful in applications that use function or status keys such as F1 and SHIFT. Setting KeyPreview to True, allows you to check for and process these keystrokes at the form level before they are sent to the active control. This way, there is no need to write code for every single control that may possibly receive a keystroke event.


Note: A form automatically receives all keyboard events if it does not contain any controls that are both visible and enabled. The setting of the KeyPreview property is ignored in this situation.

To restrict keyboard events checking and processing to the form level, in the form's KeyPress and KeyDown events set KeyAscii to 0, and in the form's KeyDown event set KeyCode to 0. This will prevent the controls from receiving any keyboard events.

Data Type: Integer (Boolean)

See Also:

KeyDown, KeyUp events; KeyPress event