TbrButtonMenus class
The collection of the menu items of a drop-down button, which the ButtonMenus property of a TbrButton returns. Its items are TbrButtonMenu objects, numbered from 1, and an item can have a key as well.
Dim Button As TbrButton
Set Button = ToolBar1.Buttons.Add(, "view", "View", TbrButtonStyleWholeDropDown)
Button.ButtonMenus.Add , "list", "List"
Button.ButtonMenus.Add , "icons", "Icons"
Button.ButtonMenus("list").Checked = True
Debug.Print Button.ButtonMenus.Count; Button.ButtonMenus("icons").Index
' Output:
' 2 2
A program goes through the items with For Each, or by number from 1 to Count. It cannot make a TbrButtonMenus object with New. The items are those of the menu that the button shows when its style is TbrButtonStyleDropDown or TbrButtonStyleWholeDropDown, in the order of the collection; a button whose hMenu names a menu of Windows shows that menu instead.
Numbers and keys
The number of an item is its place in the collection and in the menu. It changes when an item is added before it or removed before it. A key stays with its item. A key is any string, capital and small letters are the same, and no two items of a button have the same key. An item needs no key.
Properties
Count
The number of items in the collection. Long, read-only.
Item
Returns one item. It is the default member, so Button.ButtonMenus("list") is Button.ButtonMenus.Item("list").
Syntax: object.Item( Index ) As TbrButtonMenu
- Index
- required The number of the item, from 1 to Count, or its key as a String.
A number outside that range raises run-time error 9, and a key that no item has raises run-time error 5. Exists asks without an error.
Methods
Add
Puts an item into the menu and returns its TbrButtonMenu.
Syntax: object.Add( [ Index ] [, Key ] [, Text ] ) As TbrButtonMenu
- Index
- optional A Long: the number the new item gets. The items from that number on move up by one. Without it, or with 0, the item goes after the last one.
- Key
- optional A String by which the program can name the item.
- Text
- optional A String: the text of the item. An ampersand before a letter makes the letter the item’s mnemonic in the menu.
An Index below 0, and one above Count + 1, raises run-time error 35600, Index out of bounds. A Key that another item has raises run-time error 457, and the collection is as it was.
Clear
Removes every item.
Syntax: object.Clear
Exists
Returns whether the collection has an item of a number or a key, so that a program can ask before Item raises an error.
Syntax: object.Exists( Index ) As Boolean
- Index
- required The number or the key to look for.
Remove
Removes one item. The items after it move down by one.
Syntax: object.Remove Index
- Index
- required The number or the key of the item. One that the collection does not have raises the error that Item raises for it.
See Also
- ToolBar class
- TbrButton class – the button that has the menu
- TbrButtonMenu class – one menu item