Difference between revisions of "Catch KeyPresses over whole form"

From HashVB
Jump to: navigation, search
 
m (Added VB6 header)
 
Line 1: Line 1:
 +
{{VB6}}
 
A common question emerges from a need to catch keypresses form-wide.
 
A common question emerges from a need to catch keypresses form-wide.
  
Line 5: Line 6:
 
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.
 
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 :)
+
Voila :o)

Latest revision as of 14:01, 9 November 2005

float
 This article is based on Visual Basic 6. Find other Visual Basic 6 articles.

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