DesktopToolbarButton

From Xojo Documentation

Revision as of 13:16, 26 March 2022 by JLeroy (talk | contribs) (Replaced Me.Add with Me.AddButton)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

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.AddMenu(New DesktopMenuItem("Grand Blanc"))
myMenu.AddMenu(New DesktopMenuItem("Bad Axe"))
myMenu.AddMenu(New DesktopMenuItem("Flint"))

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

// Add to the toolbar
Me.AddButton(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.AddButton(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.