How to Trap Keystrokes in the Form Instead of Form's Controls (99688)
The information in this article applies to:
- Microsoft Visual Basic Standard Edition for Windows 2.0
- Microsoft Visual Basic Standard Edition for Windows 3.0
- Microsoft Visual Basic Professional Edition for Windows 2.0
- Microsoft Visual Basic Professional Edition for Windows 3.0
This article was previously published under Q99688 SUMMARY
To trap most keystrokes (see NOTE below) at the form level instead of
passing them to the form's controls, set the form's KeyPreview property to
True and use KeyAscii=0 in the Form_KeyPress event. This prevents
keystrokes from going to the form's controls.
NOTE: the technique described in this article will not intercept the ENTER
key on command buttons. Command buttons are subclassed Windows push button
controls and the ENTER key is an accelerator key that is passed to the
superclass; Visual Basic never receives it.
Also note that KeyCode=0 in the Form_KeyDown event won't prevent keystrokes
going to the form's controls. This behavior is by design.
Modification Type: | Major | Last Reviewed: | 12/12/2003 |
---|
Keywords: | KB99688 |
---|
|