Add a Button object to a Buttons collection.
ToolBar.Add[Item] ([index], [key] , [caption], [style], [image])
Buttons.Add([index], [key] , [caption], [style], [image])
index, key, caption, style, image:Variant
The ToolBar methods Add and AddItem, and Buttons.Add method, add or insert a Button object to the Buttons collection of the tool bar.
index | Optional. An integer specifying the position where you want to insert the Button object. If no index is specified, the Button is added to the end of the Buttons collection. |
key | Optional. A unique string that identifies the Button object. Use this value to retrieve a specific Button object. |
caption | Optional. A string that will appear beneath the Button object. |
style | Optional. The style of the Button object. |
0Default. The button is a regular push button. | |
1Checked. The button is a check button, which can be checked or unchecked. | |
2Button group. The button remains pressed until another button in the group is pressed. Exactly one button in the group can be pressed at any one moment. | |
3Separator. The button functions as a separator with a fixed width of 8 pixels. | |
4Place Holder. The button is like a separator in appearance and functionality, but has a settable width. | |
image | Optional. An integer or unique key that specifies a ListImage object in an associated ImageList control. |
Buttons that have the Button Group (2) style must be grouped. To distinguish a group, place all Button objects with the same style (Button Group) between two Button objects with the Separator (3) style.
When a Button object is assigned the Place Holder (4) style, you can set the value of the Width property to accommodate another control placed on the Button. If a Button object has the Button, Check, or Button Group style, the height and width are determined by the Height and Width properties.
AutoRedraw = 1
Ocx ToolBar tb
Dim btn As Button
Set btn = tb.Buttons.Add( , "open", "Open" , 0)
tb.Add , , , 3 ' Separator
tb.AddItem 1, , "New" , 0
OcxOcx tb ComboBox cb = , tb.Button(3).Left, 0, 100, 1
' The height of the ComboBox depends on the Font.
cb.Top = -cb.Height - 3
Do : Sleep : Until Me Is Nothing
GFA-BASIC 32 specific
Instead of explicitly using the Buttons collection to access a Button element, you can use a shorter notation. First, the ToolBar Ocx supports an Item property:
tb.Item(idx)tb.Buttons.Item(idx)
Like the Item method of tb.Buttons, Item is the default method of ToolBar. Therefore, a Button can be accessed as follows:
tb(idx)tb.Buttons(idx)
tb!idxtb.Buttons!idx
Each dot saves about 30 bytes of code.
To enumerate over the Buttons collection of a ToolBar Ocx, use For Each on the Ocx control directly, like:
Local btn As Button
For Each btn In tb : DoSomething(btn) : Next
{Created by Sjouke Hamstra; Last updated: 23/09/2014 by James Gaite}