PRB: Form KeyDown Displays Inconsistent Behavior (113328)
The information in this article applies to:
- Microsoft Visual Basic Standard Edition for Windows 3.0
This article was previously published under Q113328 SYMPTOMS
The KeyDown event on a Form that has KeyPreview set to True may not fire
when certain controls have the focus and arrow keys are pressed. Also, the
ENTER key won't show up in the KeyPreview if the focus is on a command
button.
CAUSE
When any of the following controls have the Focus, pressing the arrow
keys will not cause the Form_KeyDown event to fire: - Option Button
- Command Button
- Check Box
- 3D Check Box
- 3D Option Button
- 3D GroupPushButton
This is not the case when controls that accept Text input, such as a text
box, have the focus. In the case of a control that accepts text input,
you'll find that the Form_KeyDown event fires normally.
STATUS
This behavior is by design. The problem is that these controls are
subclassed off a default control type provided by Windows. For more
information, please see the Visual Basic version 3.0 "Professional Features
Book 1" manual, "Control Development Guide," page 87, the paragraph that
begins, "If Click were implemented ..."
The superclass in Windows treats these keys in a special way, so that the
control always gets the keystroke before the form does. When the control
itself handles the event, it can reflect the keystroke back to the form for
the KeyPreview. But if the superclass handles the event, the control must
also avoid handling it in order to prevent conflicts, so there is no way to
reflect the keystroke back to the form.
Modification Type: | Minor | Last Reviewed: | 1/9/2003 |
---|
Keywords: | kbprb KB113328 |
---|
|