Adds a Tab to a Tabs collection in a TabStrip control and returns a reference to the newly created Tab object.
TabStrip.Add[Item]( index, key, text, image, ocx)
Tabs.Add( index, key, text, image, ocx)
index, key, text, image, ocx: Variant exp
The TreeView Ocx has the AddItem and Add methods, which act exactly the same. The Tabs object supports the Add method only.
index | An integer specifying the position where you want to insert the Tab. If you don't specify an index, the Tab is added to the end of the Tabs collection. |
key | Optional. A unique string that can be used to retrieve the Tab with the Item method. |
text | Optional. The string that appears on the Tab. This is equivalent to setting the Caption property of the new Tab object after the object has been added to the Tabs collection. |
image | Optional. The index of an image in an associated ImageList control. This is equivalent to setting the Image property of the new Tab object after the object has been added to the Tabs collection. |
ocx | Optional. The container Ocx control to display in the client area of the TabStrip. |
Use the Key property to reference a member of the Tabs collection if you expect the value of an object's Index property to change, such as by dynamically adding objects to or removing objects from the collection. The Tabs collection is a 1-based collection.
As a Tab object is added it is assigned an index number, which is stored in the Tab object's Index property. This value of the newest member is the value of the Tab collection's Count property.
Because the Add method returns a reference to the newly created Tab object, it is most convenient to set properties of the new Tab using this reference.
Form Hidden Center frm1 = "TabStrip", , , 400, 300
Ocx TabStrip tbs = , 20, 20, ScaleWidth - 40, ScaleHeight - 40
Ocx Frame fr1 = "Tab #1"
Ocx Frame fr2 = "Tab #2"
Ocx Frame fr3 = "Tab #3"
Ocx Frame fr4 = "Tab #4"
Dim tab As Tab
tbs.Tabs.Add 1, , fr1.Caption , , fr1
tbs.AddItem 2, , fr2.Caption, , fr2
tbs.Add 3, , fr3.Caption, , fr3
Set tab = tbs.AddItem(4, , , , fr4)
tab.Caption = fr4.Caption
frm1.Show
tbs(2).Selected = True
Do
Sleep
Until Me Is Nothing
This example shows just one way to add Frame OCXs as containers to the Tabs collection.
Note - There are several ways to add containers to a TabStrip Ocx control. See the description of the TabStrip control.
GFA-BASIC 32 specific
Instead of explicitly using the Tabs collection to access a Tab element, you can use a shorter notation. First, the TabStrip Ocx supports an Item property:
tbs.Item(idx)tbs.Tabs.Item(idx)
Like the Item method of tbs.Tabs, Item is the default method of TabStrip. Therefore, a Tab object can be accessed as follows:
tbs(idx)tbs.Tabs(idx)
tbs!idxtbs.Tabs!idx
Each dot saves about 30 bytes of code.
To enumerate over the Tabs collection of a TabStrip Ocx, use For Each on the Ocx control directly, like:
Local tab1 As Tab
For Each tab1 In tbs
DoSomething(tab1)
Next
{Created by Sjouke Hamstra; Last updated: 17/02/2022 by James Gaite}