Catch KeyPresses over whole form

From HashVB
Revision as of 01:21, 20 October 2005 by Wakjah (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

A common question emerges from a need to catch keypresses form-wide.

Usually, when you have one or more controls on a form, a control, not the form, will have focus. This means that the form will not receive keypresses in its KeyPress, KeyDown and KeyUp events, which can cause difficulty with things like dialogs when trying to catch the escape key.

The solution to this is extremely simple: all you need to do is go into the properties box for the form, and set KeyPreview to True.

Voila :)