Class
ToolbarButton (deprecated)
Warning
This item was deprecated in version 2021r3. Please use DesktopToolbarButton as a replacement.
Description
A button for a Toolbar. Use the ToolbarButton class to create the items in cross-platform toolbars.
Properties
Name |
Type |
Read-Only |
Shared |
---|---|---|---|
Enumerations
ToolbarButton.ButtonStyles
ButtonStyles
Specifies the type of button.
enum |
Description |
---|---|
PushButton |
The ToolButton is a pushbutton. |
ToggleButton |
The ToolbarButton is a button that toggles between its normal and depressed state. It does not affect the state of any other Toggle buttons in the Toolbar. On macOS, only a single ToggleButton may be in the "Pressed" state at one time. Pressing one changes the state of the other toggle buttons, effectively making them work similarly to RadioButtons. |
Separator |
The ToolbarButton is a separator. Not supported on macOS. |
DropDown |
The ToolbarButton is a drop-down menu. On Windows, an arrow is drawn by default. To specify the menu, assign it to the Menu property of the DesktopToolbarButton class. Handle the selected menu item in the MenuItemSelected event of the DesktopToolbar class. See the example for the ToolbarButton class. |
SeparateDropDown |
The ToolbarButton is a drop-down menu with a separate down arrow on its right. There is room for the caption and the icon. To specify the menu, assign it to the Menu property of the DesktopToolbarButton class. Handle the selected menu item in the MenuItemSelected event of the DesktopToolbar class. See the example for the DesktopToolbarButton class. |
Space |
The ToolbarButton is a fixed-width space between ToolbarButtons. This is not supported on Windows, so no extra button or space appears. |
FlexibleSpace |
The ToolbarButton is a variable-width space between ToolbarButtons. It right-aligns the buttons to its right as the window is resized. This is not supported on Windows, so no extra space or button will be inserted. |
Property descriptions
ToolbarButton.ButtonStyle
ButtonStyle As Integer
Determines the type of button.
Get and set this property using the ButtonStyles enumeration.
ToolbarButton.Caption
Caption As String
The caption of the ToolbarItem.
This property can be set inside the IDE or programmatically.
To set an accelerator character, precede the character in the Caption with an ampersand. In order to show an ampersand in the Caption, use two ampersands in a row.
This code sets the caption of the ToolBarItem to "Bold".
Me.Caption = "Bold"
ToolbarButton.Enabled
Enabled As Boolean
True if the ToolbarItem is enabled.
ToolbarButton.Icon
Icon As Picture
The picture to be displayed by the ToolbarButton.
This example adds icons to the Cities menu and each MenuItem in the Initialized event of the Toolbar.
DropDownButton = New ToolButton
DropDownButton.ButtonStyle = ToolbarButton.ButtonStyles.DropDown
DropDownButton.Caption = "Cities"
' create a menu
Var myMenu As New MenuItem
Var myMenuItem1 As New MenuItem
Var myMenuItem2 As New MenuItem
Var myMenuitem3 As New MenuItem
DropDownButton.Name = "Cities Menu"
myMenu.Text = "Cities"
myMenu.Icon = IndiaImage
myMenuItem1.Text = "Grand Blanc"
myMenuItem2.Text = "Bad Axe"
myMenuitem3.Text = "Flint"
' icons added to the project
myMenuItem1.Icon = SaturnImage
myMenuItem2.icon = VenusImage
myMenuItem3.icon = UranusImage
myMenu.Add(myMenuItem1)
myMenu.Add(myMenuItem2)
myMenu.Add(myMenuItem3)
' assign the new menu to the toolitem..
DropDownButton.Menu = myMenu
' add to the toolbar
Me.Add(DropDownButton)
ToolbarButton.Menu
Menu As MenuItem
The menu that is used with a button of style DropDown or SeparateDropDown. Use the ButtonStyle property to set the type of button.
This example is in the ToolbarButton example discussed on the page for this class. This code is in the Initialized event of the ToolbarButton. It builds the menu, attaches it to a DropDownButton, and adds it to the toolbar.
DropDownButton = New ToolbarButton
DropDownButton.ButtonStyle = ToolbarButton.ButtonStyles.DropDown
DropDownButton.Caption = "Cities"
' create a menu
Var myMenu As New MenuItem
Var myMenuItem1 As New MenuItem
Var myMenuItem2 As New MenuItem
Var myMenuitem3 As New MenuItem
DropDownButton.Name = "Cities Menu"
myMenu.Text = "Cities"
myMenuItem1.Text = "Grand Blanc"
myMenuItem2.Text = "Bad Axe"
myMenuitem3.Text = "Flint"
myMenu.Add(myMenuItem1)
myMenu.Add(myMenuItem2)
myMenu.Add(myMenuItem3)
' assign the new menu to the toolitem..
DropDownButton.DMenu = myMenu
' add to the toolbar
Me.Add(DropDownButton)
ToolbarButton.Name
Name As String
The name of the ToolbarItem.
ToolbarButton.Pressed
Pressed As Boolean
True if the ToolbarButton was pressed. It can be used to set the toggled state of a toggle-style ToolbarButton at runtime.
ToolbarButton.Tag
Tag As Variant
A “hidden” value associated with the toolbar item.
The tag is accessible via code when the user chooses the toolbar item but, unlike the Caption property, is not displayed in the toolbar.
This example is in the Toolbar Initialized event of the main window.
Me.SaveButton.Tag = folderItemToSave
ToolbarButton.Tooltip
Tooltip As String
The tooltip that is displayed when the pointer is over the ToolbarItem.
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
Compatibility
All project types on all supported operating systems.
See also
ToolbarItem parent class; Toolbar, ToolbarItem classes.