Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleUse the TabStrip control with frames
DescriptionThis example shows how to use the TabStrip control with frames in Visual Basic 6. It hides the frames and when the user clicks a tab, it makes the corresponding frame visible.
KeywordsTabStrip, Frame
CategoriesControls
 
Thanks to Eric Groen.

The program uses a different frame for each tab. When the user clicks a tab, it sets Visible = True for the corresponding frame.

 
Private Sub Form_Load()
    ControlTabs Me, TabStrip1, TabStrip1.SelectedItem.Index
End Sub

Private Sub TabStrip1_Click()
    ControlTabs Me, TabStrip1, TabStrip1.SelectedItem.Index
End Sub

Private Sub ControlTabs(ByVal oForm As Form, _
                        ByVal oTabStrip As TabStrip, _
                        ByVal iTabIndex As Integer)
'======================================================================
'Description    :Handles visibility of frames within a
' TabStrip control.
'                This sub requires number of frames =
' number of tabs.
'Parameters     :oForm      = Name of parent form;
'                oTabStrip  = Name of TabStrip control;
'                iTabIndex  = Tab index.
'Variables      :iTabCnt    = Number of tabs in TabStrip
' control;
'                iCntFrames = Number of frames on form.
'Author         :E.Groen / www.yachtgroup.com
'Date           :13.04.2001
'Changed        :-
'======================================================================
    Dim iTabCnt, iCntFrames As Integer
    On Error GoTo Error_ControlTabs
    
    '[Frame = 0 based, TabStrip = 1 based therefore:
    ' equalize].
    iTabCnt = (oTabStrip.Tabs.Count - 1)
    iTabIndex = (iTabIndex - 1)
    
    '[Loop through the indexes of the Frame control on your
    ' parent
    'Form. If this index matches the number of the selected
    ' tab then
    'leave only this tab visible].
    For iCntFrames = 0 To iTabCnt
        oForm.Frame1(iCntFrames).Visible = False
        If iCntFrames = iTabIndex Then _
            oForm.Frame1(iCntFrames).Visible = True
    Next iCntFrames
    
    Exit Sub
    
Error_ControlTabs:
    '[Raise error when number of Frames <> number of tabs
    'else catch other error].
    Select Case Err.Number
        Case 340: MsgBox "Frame index(" & iCntFrames & ") " & _
            "doesn't exist in the ControlArray." & _
                  vbCrLf & "Make sure you add this frame to " & _
                      "your TabStrip control.", _
                  vbCritical, "Error " & Err.Number
        Case Else: MsgBox Err.Description, vbCritical, _
            "Error " & Err.Number
    End Select
End Sub
 
This technique is particularly useful in older versions of Visual Basic. In VB6, you can use the Microsoft Tabbed Dialog Control.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated