Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Tabs in VB6

Status
Not open for further replies.

Perilous1

IS-IT--Management
Mar 10, 2005
171
US
Is there any way to have Form tabs in VB6. As in, click on a tab at the bottom of a form and it displays another form in place of the first. I know it can be easily done with a button, but a tab seems so much more elegant.
 
You can certainly do it with a TabStrip control which you'll find if you tick the Microsoft Windows Common Controls component in your toolbox.

The tabs aren't an automatic feature though, you'll have to do some programming in order to get them to reflect the forms that are open. (Assuming you're talking about an MDI application?)

For starters, you can't place a TabStrip directly onto an MDI parent form, you'll need to add something like a PictureBox, set it's Align property to Bottom and then draw your TabStrip on it.

Then your easiest solution is to use a Timer to keep adding and removing and renaming the tabs as you open and close the forms. Here's some code I wrote a while ago to do exactly that. It assumes your TabStrip is called "tab_WindowNav", and that your form also has an ImageView control called "il_WNav" which this code uses for displaying an icon on each tab to match the icons of your MDI child forms.

Code:
  For Each Frm In Forms
    If (Frm.Name <> "YourMDIParentFormNameHere") Then
      If ((Frm.MDIChild = True) And (Frm.Visible = True)) Then
        AddTab = True
        If (tab_WindowNav.Tabs.Count <> 0) Then
          For Each tb In tab_WindowNav.Tabs
            If (tb.Key = Frm.Name) Then
              If (tb.Caption <> Frm.Caption) Then tb.Caption = Frm.Caption: TabChanged = True
              AddTab = False
            End If
          Next tb
        End If
        If (AddTab = True) Then
          IK& = -1
          For Each img In il_WNav.ListImages
            If (img.Key = Frm.Name) Then IK& = img.Index
          Next img
          If (IK& = -1) Then
            Set newimg = il_WNav.ListImages.add(, Frm.Name, Frm.Icon)
            IK& = newimg.Index
          End If
          tab_WindowNav.ImageList = il_WNav
          NewTab = tab_WindowNav.Tabs.add(, Frm.Name, "", IK&)
          tab_WindowNav.Visible = (tab_WindowNav.Tabs.Count <> 0)
        End If
      End If
    End If
  Next Frm

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top