Library code snippets
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.
Related articles
Related discussion
-
Problem with migration to C# (CoCreateInstanceEx)
by LRollison (1 replies)
-
VB6 Problem Creating Shortcuts
by rb1177 (0 replies)
-
how can i open a file
by kyawswarhtun (0 replies)
-
how to save any one form what i want?
by blackguy (5 replies)
-
Build an MP3 Player
by soybees (4 replies)
Related podcasts
-
Christian Beauclair
14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...
Private Sub FormLoad()
SSTab1.Tab = 0
Call SSTab1Click(0)
End Sub
Private Sub Option1_GotFocus()
Me.Caption = "Option1"
End Sub
Private Sub Option2_GotFocus()
Me.Caption = "Option2"
End Sub
Private Sub PreventTab()
Dim ctl As Control, ctl2 As Control
On Error Resume Next
For Each ctl In Me.Controls
If TypeOf ctl.Container Is SSTab Then
If (TypeOf ctl Is Frame) Or (TypeOf ctl Is PictureBox) Then
' define TabStop for all controls being childs for ctl:
For Each ctl2 In Me.Controls
If ctl2.Container.Name = ctl.Name Then
ctl2.TabStop = (ctl.Left > 0)
' If ctl.Left < 0 Then Debug.Print ctl2.Name
End If
Next ctl2
Else
ctl.TabStop = (ctl.Left > 0)
End If
End If
Next ctl
On Error GoTo 0
End Sub
Private Sub SSTab1_Click(PreviousTab As Integer)
Call PreventTab
End Sub
It will not work if some control has Frame or PictureBox object as its container (and this container object is placed on a tab of SSTab control). The possible reason is that the Left property will return positive value for such a control. But... it will return still negative for the container's Left property. So, it's necessary to modify PreventTab() to go thru the whole hierarchy of containers on each Tab - this can be made by means of recursion, for example. And this is not such a simple task as may seem!
This thread is for discussions of Tabbed Dialog control tab glitch.