Difference between revisions of "Catch KeyPresses over whole form"

From HashVB
Jump to: navigation, search
(No difference)

Revision as of 01:21, 20 October 2005

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