user1927182
user1927182

Reputation: 103

Shift-tab issue

I am new to VB but working on a VB project now. I ran into a strange problem about Shift-Tab.

The tabbing order is correct where it will go through all the textboxes, checkboxes, etc to the Accept and Cancel button at the end of the form, then cycle back to the beginning of the form.

However, if you Shift-Tab, it will skip the Accept and Cancel button. It works correctly for all other controls though.

The Tab Indices seem correct to me.

Does anyone have any idea what might be the cause? I'm at my wits end so any help would be greatly appreciated.

Upvotes: 1

Views: 999

Answers (1)

wqw
wqw

Reputation: 11991

Check for Shift+Tab on EnterFocus event of the UserControl like this

Option Explicit

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal VKey As Long) As Integer

Public Function IsKeyPressed(ByVal lVirtKey As KeyCodeConstants) As Boolean
    IsKeyPressed = ((GetAsyncKeyState(lVirtKey) And &H8000) = &H8000)
End Function

Private Sub UserControl_EnterFocus()
    If IsKeyPressed(vbKeyTab) And IsKeyPressed(vbKeyShift) Then
        cmdCancel.SetFocus
    End If
End Sub

Upvotes: 1

Related Questions