Export (0) Print
Expand All

Visual Basic: Windows Controls

Visual Studio 6.0

TabStrip Control

See Also    Example    Properties    Methods    Events

A TabStrip control is like the dividers in a notebook or the labels on a group of file folders. By using a TabStrip control, you can define multiple pages for the same area of a window or dialog box in your application.




The control consists of one or more Tab objects in a Tabs collection. At both design time and run time, you can affect the Tab object's appearance by setting properties. You can also add and remove tabs using the Properties Page of the TabStrip control at design time, or add and remove Tab objects at run time using methods.

The Style property determines whether the TabStrip control looks like push buttons (Buttons) or notebook tabs (Tabs). At design time when you put a TabStrip control on a form, it has one notebook tab. If the Style property is set to tabTabs, then there will be a border around the TabStrip control's internal area. When the Style property is set to tabButtons, no border is displayed around the internal area of the control, however, that area still exists.

To set the overall size of the TabStrip control, use its drag handles and/or set the Top, Left, Height, and Width properties. Based on the control's overall size at run time, Visual Basic automatically determines the size and position of the internal area and returns the Client-coordinate properties ClientLeft, ClientTop, ClientHeight, and ClientWidth. The MultiRow property determines whether the control can have more than one row of tabs, the TabWidthStyle property determines the appearance of each row, and, if TabWidthStyle is set to tabFixed, you can use the TabFixedHeight and TabFixedWidth properties to set the same height and width for all tabs in the TabStrip control.

The TabStrip control is not a container. To contain the actual pages and their objects, you must use Frame controls or other containers that match the size of the internal area which is shared by all Tab objects in the control. If you use a control array for the container, you can associate each item in the array with a specific Tab object, as in the following example:

Option Explicit
Private mintCurFrame As Integer' Current Frame visible

Private Sub Tabstrip1_Click()
   If Tabstrip1.SelectedItem.Index = mintCurFrame _
      Then Exit Sub ' No need to change frame.
   ' Otherwise, hide old frame, show new.
   Frame1(Tabstrip1.SelectedItem.Index).Visible = True
   Frame1(mintCurFrame).Visible = False
   ' Set mintCurFrame to new value.
   mintCurFrame = Tabstrip1.SelectedItem.Index
End Sub

Note   When grouping controls on a container, you must use the show/hide strategy shown above instead of using the Zorder Method to bring a frame to the front. Otherwise, controls that implement access keys (ALT + access key) will still respond to keyboard commands, even if the container is not the topmost control. Also note that you must segregate groups of OptionButton controls by placing each group on its own container, or else all OptionButtons on the form will behave as one large group of OptionButtons.

Tip   Use a Frame control with its BorderStyle set to None as the container instead of a PictureBox control. A Frame control uses less overhead than a PictureBox control.

The Tabs property of the TabStrip control is the collection of all the Tab objects. Each Tab object has properties associated with its current state and appearance. For example, you can associate an ImageList control with the TabStrip control, and then use images on individual tabs. You can also associate a ToolTip with each Tab object.

Distribution Note   The TabStrip control is part of a group of custom controls that are found in the MSCOMCTL.OCX file. To use the TabStrip control in your application, you must add the MSCOMCTL.OCX file to the project. When distributing your application, install the MSCOMCTL.OCX file in the user's Microsoft Windows SYSTEM folder. For more information on how to add a custom control to a project, see the Programmer's Guide.

© 2014 Microsoft