TbrButton class
One button of a ToolBar: its caption, its picture, its style and state, its place, and the menu items of a drop-down button. A program gets one from the TbrButtons collection, and from that collection’s Add method.
Dim Button As TbrButton
Set Button = ToolBar1.Buttons.Add(, "bold", "Bold", TbrButtonStyleCheck)
Button.ToolTipText = "Bold"
Button.Value = TbrButtonValuePressed
Debug.Print Button.Caption; Button.Value
' Output:
' Bold 1
A program cannot make a TbrButton object with New. A variable that holds one keeps it as long as the toolbar does not make its window again, which a change of some properties of the toolbar does. A button that was removed from the collection no longer reaches the toolbar.
Style and state
The Style of a button is a member of TbrButtonStyleConstants. A button of style TbrButtonStyleCheck or TbrButtonStyleCheckGroup is pressed or not by its Value, and the user changes it with a click.
Another Style keeps the button’s caption, and releases the button if it was pressed. A value that is not a member raises run-time error 380.
The state of a button is Enabled, Visible, Value, MixedState, HighLighted and, while the pointer is over it, Hot. A disabled button shows its caption and picture greyed and takes no click. A hidden one takes no room on the toolbar: the buttons after it move up, and its Left, Top, Width and Height read 0.
Width
A button is as wide as the toolbar’s ButtonWidth says, or wider where its picture and caption need the room. AutoSize makes the width follow the caption and the picture, and CustomWidth gives it a width of its own.
Dim Wide As TbrButton, Narrow As TbrButton
Set Narrow = ToolBar1.Buttons.Add(, "a", "A")
Set Wide = ToolBar1.Buttons.Add(, "b", "A button with a long caption")
Dim Standard As Single
Standard = Narrow.Width
Narrow.AutoSize = True
Wide.AutoSize = True
Debug.Print Narrow.Width < Standard
Debug.Print Wide.Width > Standard
' Output:
' True
' True
Properties
AutoSize
Whether the button is as wide as its caption and its picture need, in place of the toolbar’s ButtonWidth. Boolean. Default: False. A button with AutoSize True takes no CustomWidth.
ButtonMenus
The menu items of a drop-down button. A TbrButtonMenus object, read-only. The button shows them when its style is TbrButtonStyleDropDown or TbrButtonStyleWholeDropDown, unless its hMenu names a menu.
Caption
The text of the button. String. It is the default member. An ampersand before a letter makes the letter the mnemonic of the button, unless NoPrefix is True.
CustomWidth
The width the program gives the button, in the container’s scale units. Single. Default: 0, which leaves the width to the toolbar.
A negative value raises run-time error 380.
Description
The text by which the customization dialog of Windows names the button. String. Default: empty. See Customizing.
Enabled
Whether the button takes a click. Boolean. Default: True.
ForeColor
The color of the caption. OLE_COLOR. Default: vbButtonText. A button that is hot while the toolbar’s HotTracking is True draws its caption in vbHighlightText.
Height
The height of the button, in the container’s scale units. Single, read-only.
An assignment to Height, Left, Top or Width raises run-time error 383.
hMenu
The handle of a menu of Windows that the program has made, which a drop-down button shows in place of its ButtonMenus. LongPtr. Default: 0. The toolbar does not destroy the menu. A chosen item raises ButtonMenuClick2 with the item’s identifier.
HighLighted
Whether the button is marked: it is drawn in the highlighted state. Boolean. Default: False. A program with visual styles draws the button’s picture blended instead.
Hot
Whether the button is the toolbar’s hot button. Boolean. Assigned True it makes the button hot, and assigned False it takes the hot state away if the button has it. Each change raises ButtonHotChanged. See Hot buttons.
ID
The number by which the toolbar’s window knows the button, in the messages that Windows sends about it. Long, read-only. It stays with the button when the button moves.
Image
The picture of the button: its number in the toolbar’s ImageList, or its key. Variant. Default: 0, which is no picture. It is what the program gave to the property or to Add: a key stays a key.
A key that the image list does not have, or a key when the toolbar has no image list, raises run-time error 35601, Element not found. A negative number raises error 35600, Index out of bounds, and the button keeps its picture after either error.
ImageIndex
The number of the button’s picture in the image list. Long, read-only. It is 0 for a button without a picture, and it is the number that a key stands for.
Index
The number of the button in the TbrButtons collection, from 1. Long, read-only. It changes when a button is added or removed before this one, and not when the button is moved on the toolbar.
Key
The key of the button in the collection. String. Empty for a button without a key.
An assignment gives the button another key, and the collection no longer finds it by the old one. An empty string takes the key away. A key that another button has raises run-time error 457, and the button keeps its key.
Left
The distance between the left edge of the toolbar and the left edge of the button, in the container’s scale units. Single, read-only. See Height.
MixedState
Whether the button is drawn in the indeterminate state, as a check button is that is neither pressed nor released. Boolean. Default: False.
NoImage
Whether the button is drawn without a picture, and without room for one, even where it has one. Boolean. Default: False.
NoPrefix
Whether an ampersand in the caption is an ordinary character, without a mnemonic. Boolean. Default: False.
Position
The button’s place on the toolbar, counted from 1. Long. It is the number of the button as the user sees it, which differs from Index once a button has moved. Assigned a number, it moves the button there, and the buttons it passes shift by one.
A value that is the button’s own position raises run-time error 380, because nothing moves. A value above the number of buttons moves the button to the end.
Style
What kind of button it is. A member of TbrButtonStyleConstants. Default: the style the button was added with. See Style and state.
Tag
A value of the program’s own, which the toolbar does not use. Variant: unlike the Tag of the control it holds a value of any type, an object included, which is assigned with Set.
A new button has an empty string.
ToolTipText
The text shown in a small window when the pointer rests on the button, while the toolbar’s ShowTips is True. String. Default: empty.
Top
The distance between the top edge of the toolbar and the top edge of the button, in the container’s scale units. Single, read-only. See Height.
Value
Whether the button is pressed. A member of TbrButtonValueConstants. Default: TbrButtonValueUnpressed.
Pressing a check group button releases the other buttons of its group, and a check button changes alone.
Visible
Whether the button is shown. Boolean. Default: True.
A hidden button keeps its Position and its place in the collection, and the buttons after it move up on the toolbar.
Width
The width of the button, in the container’s scale units. Single, read-only. See Height.
See Also
- ToolBar class
- TbrButtons class – the collection of the buttons
- TbrButtonMenus class – the menu items of a drop-down button
- TbrButtonStyleConstants – the values of Style
- TbrButtonValueConstants – the values of Value