BUG: UserControl SHIFT+TAB Does Not Follow Tab Sequence
ID: Q192208
|
The information in this article applies to:
-
Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 6.0
SYMPTOMS
When tabbing through constituent controls contained on a UserControl in
reverse order (SHIFT+TAB), only the first constituent control is part of
the reverse tab sequence. All controls should be part of the reverse tab
sequence unless the TabStop property is set to False. Tabbing forward
through the controls works as expected.
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed
at the beginning of this article.
MORE INFORMATION
Steps to Reproduce Behavior
- Start a new Standard EXE project in Visual Basic. Form1 is created by default.
- From the File menu, add an ActiveX Control project. UserControl1 is
created by default.
- Add three TextBox controls to UserControl1.
- Close the UserControl1 window and add an instance of UserControl1 to
Form1.
- Add a CommandButton to Form1.
- Save and run the Project.
- First, tab through all the controls using the TAB key. Now tab backwards through the controls using the SHIFT+TAB key combination. Observe that the only constituent control that receives focus is the first TextBox.
Bug: Only the first control on the UserControl is included in the
reverse tabbing sequence.
- Return to design mode and add the following code to UserControl1:
Option Explicit
Private Declare Function GetKeyState Lib "user32" _
(ByVal nVirtKey As Long) As Integer
Private Sub UserControl_EnterFocus()
Static bEntered As Boolean
Static FirstCtrl As Control
Static LastCtrl As Control
Dim State As Integer
If (GetKeyState(vbKeyTab) And &H1110) = 0 Then
Exit Sub 'Not entering by pressing Tab, maybe mouse click.
End If
State = GetKeyState(vbKeyShift) And &H1110 'Eliminate 1st bit.
If bEntered Then 'If already FirstCtrl and LastCtrl are found.
If State = 0 Then
FirstCtrl.SetFocus 'Shift key up.
Else
LastCtrl.SetFocus 'Shift key down.
End If
Else 'If entering first time.
Dim Ctrl As Control
Dim nFirst As Integer, nLast As Integer
On Error Resume Next 'There may be controls without tabindex.
For Each Ctrl In Controls
If Ctrl.TabIndex <= nFirst Then 'Minimum value.
nFirst = Ctrl.TabIndex
Set FirstCtrl = Ctrl
ElseIf Ctrl.TabIndex >= nLast Then 'Maximum value.
nLast = Ctrl.TabIndex
Set LastCtrl = Ctrl
End If
Next
bEntered = True 'Entered once.
End If
End Sub
- Save and run the project again. This time the SHIFT+TAB sequence
loops through all the controls in the UserControl.
Additional query words:
kbDSupport kbDSD kbVBp kbVBp600bug kbCtrlCreate
Keywords : kbGrpVB
Version : WINDOWS:6.0
Platform : WINDOWS
Issue type : kbbug