ToolbarButton

From Xojo Documentation

Class (inherits from ToolbarItem)


New in 2019r2

A button for a Toolbar. Use the ToolbarButton class to create the items in cross-platform toolbars.

Properties
ButtonStyle Icon Pressed
Caption Menu Tag
Enabled Name Tooltip

Sample Code

This code creates a ToolbarButton of style Drop-down and adds it to the toolbar. The window has a property DropDownButton as ToolbarButton. The Open event of the Toolbar in the window has the following code:

Var dropDownButton As New ToolbarButton
dropDownButton.ButtonStyle = ToolbarButton.ButtonStyles.DropDownMenu
dropDownButton.Caption = "Cities"
dropDownButton.Name = "CitiesMenu"

// Create a menu
Var myMenu As New MenuItem
myMenu.Add(New MenuItem("Grand Blanc"))
myMenu.Add(New MenuItem("Bad Axe"))
myMenu.Add(New MenuItem("Flint"))

// Assign the new menu to the toolitem..
dropDownButton.Menu = myMenu

// Add to the toolbar
Me.Add(dropDownButton)

The following code in the Toolbar's MenuItemSelected event handles the menu selection.

Event MenuItemSelected(button As ToolbarItem, selectedItem As MenuItem)
Select Case selectedItem.Text
Case "Grand Blanc"
MessageBox("You chose Grand Blanc from the " + selectedItem.Name + " .")
Case "Flint"
MessageBox("You chose Flint from the " + selectedItem.Name + " .")
Case "Bad Axe"
MessageBox("you chose Bad Axe from the " + selectedItem.Name + " .")
End Select
End Event

This code adds a toggle style button to the toolbar. This code is in the Open event of the Toolbar:

Var toggleButton As New ToolbarButton
toggleButton.ButtonStyle = ToolbarButton.ButtonStyles.ToggleButton
toggleButton.Caption = "Toggle"
Me.Add(toggleButton)

This code will push a toggle style button that is the first button on a toolbar (code is in the Open event handler of the Toolbar):

ToolButton.Pressed = Not ToolbarButton.Pressed

See Also

Toolbar, ToolbarItem classes.