ToolButton
From Xojo Documentation
This item was deprecated in version 2019r2. Please use ToolbarButton as a replacement. |
Class (inherits from ToolItem)
A button for a Toolbar. Use the ToolButton class to create the items in cross-platform toolbars.
Properties | |||||||||
|
Class Constants
The following class constants can be used to specify the style of the ToolButton.
Class Constants | Description |
---|---|
ToolStylePushButton | The ToolButton is a push button. Clicking the button calls the Action event of the toolbar. |
ToolStyleToggleButton | The ToolButton toggles when pushed. Clicking the button calls the Action event of the toolbar. |
ToolStyleSeparator | The ToolButton is a separator. (Supported on Windows and Linux only.) |
ToolStyleDropDown | The ToolButton displays a drop-down menu when clicked. On Windows, the button displays with a drop-down indicator and clicking anywhere on the button displays the drop-down menu. On Linux this style works the same as ToolStyleSeparateDropDown. A drop-down indicator does not appear on macOS. The DropDownMenuAction event on the toolbar is called when a menu item is selected. |
ToolStyleSeparateDropDown | The ToolButton displays a separate drop-down indicator in the button. Clicking this indicator displays the drop-down menu. Clicking the main button area calls the Action event for the toolbar. The DropDownMenuAction event on the toolbar is called when a menu item is selected. On macOS this style works the same as ToolStyleDropDown. |
ToolStyleSpace | The ToolButton is a fixed-width space. (Supported on macOS and Linux only.) |
ToolStyleFlexibleSpace | The ToolButton is a flexible space. (Supported on macOS and Linux only.) |
Sample Code
This code creates a ToolButton of style Drop-down and adds it to the toolbar. The window has a property DropDownButton as ToolButton. The Open event of the Toolbar in the window has the following code:
Dim dropDownButton As New ToolButton
dropDownButton.Style = ToolButton.ToolStyleDropDown
dropDownButton.Caption = "Cities"
dropDownButton.Name = "CitiesMenu"
// Create a menu
Dim myMenu As New MenuItem
myMenu.Append(New MenuItem("Grand Blanc"))
myMenu.Append(New MenuItem("Bad Axe"))
myMenu.Append(New MenuItem("Flint"))
// Assign the new menu to the toolitem..
dropDownButton.DropDownMenu = myMenu
// Add to the toolbar
Me.Append(dropDownButton)
dropDownButton.Style = ToolButton.ToolStyleDropDown
dropDownButton.Caption = "Cities"
dropDownButton.Name = "CitiesMenu"
// Create a menu
Dim myMenu As New MenuItem
myMenu.Append(New MenuItem("Grand Blanc"))
myMenu.Append(New MenuItem("Bad Axe"))
myMenu.Append(New MenuItem("Flint"))
// Assign the new menu to the toolitem..
dropDownButton.DropDownMenu = myMenu
// Add to the toolbar
Me.Append(dropDownButton)
The following code in the Toolbar's DropDownMenuAction event handles the menu selection.
Event DropDownMenuAction(item As ToolItem, hitItem As MenuItem)
Select Case hitItem.Text
Case "Grand Blanc"
MsgBox("You chose Grand Blanc from the " + item.Name + " .")
Case "Flint"
MsgBox("You chose Flint from the " + item.Name + " .")
Case "Bad Axe"
MsgBox("you chose Bad Axe from the " + item.Name + " .")
End Select
End Event
Select Case hitItem.Text
Case "Grand Blanc"
MsgBox("You chose Grand Blanc from the " + item.Name + " .")
Case "Flint"
MsgBox("You chose Flint from the " + item.Name + " .")
Case "Bad Axe"
MsgBox("you chose Bad Axe from the " + item.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:
Dim toggleButton As New ToolButton
toggleButton.Style = ToolButton.ToolStyleToggleButton
toggleButton.Caption = "Toggle"
Me.Append(toggleButton)
toggleButton.Style = ToolButton.ToolStyleToggleButton
toggleButton.Caption = "Toggle"
Me.Append(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.Pushed = Not ToolButton.Pushed