DesktopToolbarButton

From Xojo Documentation

Class (inherits from DesktopToolbarItem)


New in 2021r3

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

Properties
ButtonStyle Icon Pressed
Caption Menu Tag
Enabled Name Tooltip
Enumerations
ButtonStyles

Sample Code

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

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

// Create a menu
Var myMenu As New DesktopMenuItem
myMenu.Add(New DesktopMenuItem("Grand Blanc"))
myMenu.Add(New DesktopMenuItem("Bad Axe"))
myMenu.Add(New DesktopMenuItem("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 DesktopToolbarItem, selectedItem As DesktopMenuItem)
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 Opening event of the Toolbar:

Var toggleButton As New DesktopToolbarButton
toggleButton.ButtonStyle = DesktopToolbarButton.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 Opening event handler of the Toolbar):

ToolButton.Pressed = Not DesktopToolbarButton.Pressed

See Also

DesktopToolbar, DesktopToolbarItem classes.