Tabbed Dialog control tab glitch

While not perfect, the Tabbed Dialog control (also known as the SSTab) provides a much needed improvement over the older Tab Strip control. If you're not familiar with this control, unlike it's predecessor, the Tabbed Dialog contains pages upon which you can place controls. These pages act as containers and automatically hide their subordinate controls when you click a new tab. For the most part, the control works without a hitch.

However, if you add an OCX control, such as a Masked Edit or Rich Textbox, to a page, the Tabbed Dialog may exhibit some strange behavior. Normally at runtime, when you press the [Tab] key, Visual Basic tabs between only those subordinate controls on the visible page. If the Tabbed Dialog contains an OCX control, though, it will include this control in the tab order, regardless of whether or not the page hosting the control is visible. Fortunately, there's an easy fix.

Apparently, when a control isn't visible in the Tabbed Dialog, it's because VB has moved it far off to the left of the Tabbed Dialog's left edge. When you select a tab, VB moves the appropriate controls back into Tabbed Dialog's main area. As a result, we can use this behavior to our advantage by testing a control's Left property. If it's greater than zero (visible) then we want VB to tab to it. Otherwise, we want to set the control's TabStop property to false.

The following procedure shows an example of this fix:

Private Sub PreventTab()
Dim ctl As Control
    For Each ctl In Me.Controls
        With ctl
            If TypeOf .Container Is SSTab Then
                'Not all controls have the TabStop property
                On Error Resume Next
                .TabStop = (.Left > 0)
                On Error GoTo 0
            End If
        End With
    Next ctl
End Sub

As you can see, this procedure loops through all the controls on the form, testing for those contained in the SSTab (Tabbed Dialog) control. It then sets each control's TabStop property equal to the Boolean result of the expression

.Left > 0

Controls in the visible portion of the SSTab will evaluate to True, while those off the form won't.

You might also like...

Comments

ElementK Journals

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There's no test like production” - Anon