Tab Object

Description

A Tab is an individual member of a Tabs collection.

Remarks

Visually, a Tab object appears as a rectangle protruding from a larger rectangular area or as a button adjacent to a rectangular area.

In contrast to a Page, a Tab does not contain any controls. Controls that appear within the region bounded by a TabStrip are contained on the form, as is the TabStrip.

Each Tab has its own set of properties, but has no methods or events. You must use events from the appropriate TabStrip to initiate processing of an individual Tab.

Each Tab has a unique name and index value within the collection. You can reference a Tab by either its name or its index value. The index of the first Tab is 0; the index of the second Tab is 1; and so on. When two Tab objects have the same name, you must reference each Tab by its index value. References to the name in code will access only the first Tab that uses the name.

Properties

Accelerator property, Caption property, ControlTipText property, Enabled property, Index property, Name property, Tag property, Visible property.

See Also

Page object, Tabs collection, TabStrip control.

Example

The following example accesses an individual tab of a TabStrip in several ways:

  • Using the Tabs collection with a numeric index.
  • Using the Tabs collection with a string index.
  • Using the Tabs collection with the Item method.
  • Using the name of the individual Tab.
  • Using the SelectedItem property.
To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains a TabStrip named TabStrip1.

Private Sub UserForm_Initialize()
    Dim TabName As String

    For i = 0 To TabStrip1.Count - 1
        'Using index (numeric or string)
        MsgBox "TabStrip1.Tabs(i).Caption = " & TabStrip1.Tabs(i). _
            Caption
        MsgBox "TabStrip1.Tabs.Item(i).Caption = " & TabStrip1.Tabs _
            .Item(i).Caption

        TabName = TabStrip1.Tabs(i).Name
        MsgBox "TabName = " & TabName

        MsgBox "TabStrip1.Tabs(TabName).Caption = " & TabStrip1.Tabs _
            (TabName).Caption
        MsgBox "TabStrip1.Tabs.Item(TabName).Caption = " & TabStrip1. _
            Tabs.Item(TabName).Caption

        'Use Tab object without referring to Tabs collection
        If i = 0 Then
            MsgBox "TabStrip1.Tab1. Caption = " & TabStrip1.Tab1.Caption
        ElseIf i = 1 Then
            MsgBox "TabStrip1.Tab2. Caption = " & TabStrip1.Tab2.Caption
        EndIf

        'Use SelectedItem Property
        TabStrip1.Value = i
        MsgBox " TabStrip1.SelectedItem.Caption = " & TabStrip1. _
            SelectedItem.Caption
    Next i
End Sub