Microsoft KB Archive/149273

= BUG: Form Key Events Fire Twice with SSTab Control =

Article ID: 149273

Article Last Modified on 6/29/2004

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 16-bit Enterprise Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q149273



SYMPTOMS
If an SSTab, SSFrame or SSPanel control has the focus and a key is pressed, then all of the Form level key events (Form_KeyDown, Form_KeyPress, and Form_KeyUp) will be fired twice. This problem occurs only if the KeyPreview property of the form is set to True.



RESOLUTION
It may be possible to write code to ignore the second key event if focus is on the tab control. This could be done by utilizing a global flag variable to represent whether or not the key event had been raised before. Aside from this, the best option is to avoid writing code that depends on this functionality.



STATUS
Microsoft has confirmed this to be an issue in the Microsoft products listed at the beginning of this article.



Steps to Reproduce Behavior
 Start a new Standard EXE Project in Visual Basic, Form1 is created by default. Draw a single SSTab control onto Form1.  Change this property of Form1:   KeyPreview: True   Add this code to the form: Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) Debug.Print "Form KeyDown" End Sub

Private Sub Form_KeyPress(KeyAscii As Integer) Debug.Print "Form_KeyPress" End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer) Debug.Print "Form KeyUp" End Sub

Private Sub SSTab1_KeyDown(KeyCode As Integer, Shift As Integer) Debug.Print "SSTab KeyDown" End Sub

Private Sub SSTab1_KeyPress(KeyAscii As Integer) Debug.Print "SSTab KeyPress" End Sub

Private Sub SSTab1_KeyUp(KeyCode As Integer, Shift As Integer) Debug.Print "SSTab KeyUp" End Sub  Press F5 or select Start from the Run menu to run the application. Click once on the SSTab to ensure that it has the focus. Then press a single key on the keyboard. Observe the output in the debug window to see that each form key event has been fired twice.</li></ol>

Additional query words: kbVBp400bug kbVBp500bug kbCtrl kbVBp kbdsd kbDSupport

Keywords: kbbug KB149273

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.