A Tab object represents an individual tab in the Tabs collection of a TabStrip control.
A Tabs collection contains a collection of Tab objects.
tabstrip.Tabs(index)
tabstrip.Tabs.Item(index)
index:Variant. A value that identifies a Tab object in the Tabs collection. This may either be the Index property or the Key property of the desired Tab object.
The Tabs collection can be accessed by using the standard collection methods, such as the Item method.
At run time, use the TabStrip control to insert and remove tabs, and use Tab object to specify any of these properties for a Tab object: Caption, Image, ToolTipText, Tag, Index, and/or Key.
Use the Caption and Image properties, separately or together, to label or put an icon on a tab.
To use the Image property, put an ImageList control on the form and fill the ListImages collection with ListImage objects, each of which has an index number and an optional key, if you add one. Set the ImageList property of the TabStrip control to associate it with the TabStrip control.
Use the ToolTipText property to temporarily display a string of text in a small rectangular box at run time when the user's cursor hovers over the tab.
To return a reference to a Tab object a user has selected, use the SelectedItem or SelectedIndex properties; to determine whether a specific tab is selected, use the Selected property. These properties are useful in conjunction with the BeforeClick event to verify or record data associated with the currently-selected tab before displaying the next tab the user selects.
Each Tab object also has read-only properties you can use to reference a single Tab object in the Tabs collection: Left, Top, Height and Width.
The Tabs collection properties and methods:
Add | Clear | Count | Item | Remove
The Tab properties and methods:
Caption | Height | Index | Image | Key | Left | hWnd | Selected | TabStripName | Tag | Text | ToolTipText | Top | Width
Tab only properties:
Ocx returns an Object reference to the object that is attached to the Tab, whether it be a form, frame or image.
$Library "UpdateRT"
UpdateRuntime ' Patches GfaWin23.Ocx
Form Hidden Center frm1 = "TabStrip", , , 400, 300
// Create the tabstrip
Ocx TabStrip tbs = , 20, 20, ScaleWidth - 40, ScaleHeight - 40
// Create the four frames to go on to the four tabs you wish to create
Ocx Frame fr1 = "Tab #1"
Ocx Frame fr2 = "Tab #2"
Ocx Frame fr3 = "Tab #3"
Ocx Frame fr4 = "Tab #4"
// Populate the four frames with different OCX controls
OcxOcx fr1 Option opt1 = "Option #1", 20, 20, 80, 24
OcxOcx fr1 Option opt2 = "Option #2", 20, 50, 80, 24
OcxOcx fr2 CheckBox chk1 = "Check #1", 20, 20, 80, 24
OcxOcx fr2 CheckBox chk2 = "Check #2", 20, 50, 80, 24
OcxOcx fr3 TextBox txt1 = "TextBox #1", 20, 20, 280, 40
OcxOcx fr3 TextBox txt2 = "TextBox #2", 20, 130, 280, 40
OcxOcx fr4 Command cmd1 = "Command #1", 90, 20, 80, 24
OcxOcx fr4 Command cmd2 = "Command #2", 90, 50, 80, 24
// Create the four tabs from the pre-prepared frames
tbs.Tabs.Add 1, , fr1.Caption , , fr1
tbs.AddItem 2, , fr2.Caption, , fr2
tbs.Add 3, , fr3.Caption, , fr3
tbs.AddItem 4, , fr4.Caption , , fr4
frm1.Show
tbs(2).Selected = True
Do
Sleep
Until Me Is Nothing
Sub tbs_Change
Switch tbs.SelectedIndex
Case 1 : opt1.SetFocus
Case 2 : chk1.SetFocus
Case 3 : txt1.SetFocus
Case 4 : cmd1.SetFocus
EndSwitch
// Send the Ocx Control details to the debug page
Trace tbs.SelectedItem.Ocx
End Sub
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 tab As Tab
For Each tab In tbs : DoSomething(tab) : Next
{Created by Sjouke Hamstra; Last updated: 17/02/2022 by James Gaite}