Tabbing between radio buttons in VB6
Asked Answered
F

2

6

I have a form which consists of six radio buttons within a frame which are mutually exclusive and one command button.

I already gave different tab-index to each radio button but at the run time by pressing tab focus skipped out of the radio buttons.

so how to give focus to another radio button by pressing TAB?

Firearm answered 2/7, 2012 at 5:38 Comment(3)
That is the intended behaviour. To move focus between buttons in the same radio box, use the arrow keys.Curitiba
What I do (if possible) is give the radio buttons' captions the same keyboard shortcut. This will cause the focus to cycle between the options. I do not know if this violates any UI conventions though..Dacoit
@BrianHooper You are correct. It's worth emphasising that using the arrow keys also changes the radio button's values. This is the intended behaviour and complies with the Windows User Experience guidelines, so it should match the user's expectationsCleaner
D
2
Private Sub Option1_KeyPress(KeyAscii As Integer)
   If KeyAscii = 9 Then
      Option2.SetFocus
   End If
End Sub

KeyAscii=9 is the code for the Tab key. But you must do it for all of your radio buttons.

If you add your radio buttons belonging to the same radio button having indices 0, 1, 2 you can do it like this:

Private Sub Option1_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = 9 Then
    If Index < Option1.Count - 1 Then
        Option1(Index + 1).SetFocus
    Else
        Option1(0).SetFocus
    End If
End If
End Sub
Droughty answered 5/8, 2012 at 4:41 Comment(0)
O
3

As others have said above this is intended behaviour. If you really wish to achieve this then the only way I can think to do this is place each radio button on a separate picture box (BorderStyle = None, TabStop = False). This will then work but you won't be able to use arrow keys to move between the radio buttons, only tabbing.

Oyster answered 2/8, 2012 at 14:8 Comment(0)
D
2
Private Sub Option1_KeyPress(KeyAscii As Integer)
   If KeyAscii = 9 Then
      Option2.SetFocus
   End If
End Sub

KeyAscii=9 is the code for the Tab key. But you must do it for all of your radio buttons.

If you add your radio buttons belonging to the same radio button having indices 0, 1, 2 you can do it like this:

Private Sub Option1_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = 9 Then
    If Index < Option1.Count - 1 Then
        Option1(Index + 1).SetFocus
    Else
        Option1(0).SetFocus
    End If
End If
End Sub
Droughty answered 5/8, 2012 at 4:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.