Link to home
Start Free TrialLog in
Avatar of Melvinivitch
Melvinivitch

asked on

SSTab Key Events fired twice Bug (VB6). Workaround? Fix?

I have an SSTab control with 4 tabs. I need the user to be able to cycle through the tabs using the keystroke: alt-f ...(crtl-tab works by default, but I also need alt-f). ...

THE PROBLEM is that there's apparently a bug (see KB article: 149273) in the SSTab control whereby key events get fired twice. I'm noticing this behavior: if I click a tab and then use alt-f to switch between them, it skips a tab... Interestingly, the alt-f behavior is fine *until* I click a tab with the mouse, after which point the key event gets fired twice every time I hit alt-f...

I'm looking for a workaround, or a fix of some sort... The Knowledgebase article suggests using a global to ignore the 2nd keyevent if focus is on the sstab, but this will not work for me as I need alt-f to work regardless of what control has focus (ie, the sstab may already have focus anyway)...

Here's the code I'm using (keyPreview = true is set in form load...), and the Microsoft Knowledgebase article describing the aforementioned bug in sstab:

http://support.microsoft.com/kb/149273/EN-US/

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If Shift = vbAltMask Then
        Select Case KeyCode
            Case vbKeyF: Call moveToNextTab
        End Select
    End If
End Sub

Private Sub moveToNextTab
    If SSTab1.Tab >= 3 Then
        SSTab1.Tab = 0
    Else
        SSTab1.Tab = SSTab1.Tab + 1
    End If
End Sub
Avatar of gary_j
gary_j
Flag of United States of America image

For me, it never works, whether I've clicked on the SSTab or not -- it always jumps two
I think what is happeneing is that your moveToNextTab is causing a sstab click event

I solved it by setting a global variable:

Option Explicit
Dim g_bolClicked As Boolean

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If Shift = vbAltMask Then
        Select Case KeyCode
            Case vbKeyG: Call moveToNextTab
        End Select
    End If
End Sub

Private Sub moveToNextTab()
    If g_bolClicked = False Then
        g_bolClicked = True
        If SSTab1.Tab >= 3 Then
            SSTab1.Tab = 0
        Else
            SSTab1.Tab = SSTab1.Tab + 1
        End If
    Else
        g_bolClicked = False
    End If
End Sub
ASKER CERTIFIED SOLUTION
Avatar of rettiseert
rettiseert

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial