BUG: Form Key Events Fire Twice with SSTab Control

Last reviewed: November 19, 1996
Article ID: Q149273
The information in this article applies to:
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 16-bit and 32-bit, for Windows, version 4.0

SYMPTOMS

If an SSTab 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.

WORKAROUND

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. Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Steps to Reproduce

  1. Start Visual Basic 4.0. Form1 is created by default.

  2. Draw a single SSTab control onto Form1.

  3. Change this property of Form1: KeyPreview: True

  4. 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
    
    

  5. 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.


Additional reference words: 4.00 vb4win vb4all
KBCategory: kbprg kbbuglist
KBSubcategory: PrgCtrlsCus



THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 19, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.