Class

DesktopToolbarButton


Description

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

Enumerations

DesktopToolbarButton.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


DesktopToolbarButton.ButtonStyle

ButtonStyle As ButtonStyles

Determines the type of button.

Get and set this property using the DesktopToolbarButton enumeration.


DesktopToolbarButton.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"

DesktopToolbarButton.Enabled

Enabled As Boolean

True if the DesktopToolbarItem is enabled.


DesktopToolbarButton.Icon

Icon As Picture

The picture to be displayed by the DesktopToolbarButton.

This example adds icons to the Cities menu and each MenuItem in the Initialized event of the Toolbar.

DropDownButton = New DesktopToolButton
DropDownButton.ButtonStyle = DesktopToolbarButton.ButtonStyles.DropDown
DropDownButton.Caption = "Cities"

' create a menu
Var myMenu As New DesktopMenuItem
Var myMenuItem1 As New DesktopMenuItem
Var myMenuItem2 As New DesktopMenuItem
Var myMenuitem3 As New DesktopMenuItem

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.AddButton(DropDownButton)

DesktopToolbarButton.Menu

Menu As DesktopMenuItem

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 DesktopToolbarButton example discussed on the page for this class. This code is in the Opening event of a DesktopToolbar. It builds the menu, attaches it to a DropDownButton, and adds it to the toolbar.

DropDownButton = New DesktopToolbarButton
DropDownButton.ButtonStyle = DesktopToolbarButton.ButtonStyles.DropDownMenu
DropDownButton.Caption = "Cities"

' create a menu
Var myMenu As New DesktopMenuItem
Var myMenuItem1 As New DesktopMenuItem
Var myMenuItem2 As New DesktopMenuItem
Var myMenuitem3 As New DesktopMenuItem

DropDownButton.Name = "Cities Menu"
myMenu.Text = "Cities"

myMenuItem1.Text = "Grand Blanc"
myMenuItem2.Text = "Bad Axe"
myMenuitem3.Text = "Flint"
myMenu.AddMenu(myMenuItem1)
myMenu.AddMenu(myMenuItem2)
myMenu.AddMenu(myMenuItem3)

' assign the new menu to the toolitem..
DropDownButton.Menu = myMenu

' add to the toolbar
Me.AddButton(DropDownButton)

DesktopToolbarButton.Name

Name As String

The name of the DesktopToolbarItem.


DesktopToolbarButton.Pressed

Pressed As Boolean

True if the DesktopToolbarButton was pressed. It can be used to set the toggled state of a toggle-style DesktopToolbarButton at runtime.


DesktopToolbarButton.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

DesktopToolbarButton.Tooltip

Tooltip As String

The tooltip that is displayed when the pointer is over the DesktopToolbarItem.

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

Compatibility

Desktop projects on all supported operating systems.

See also

DesktopToolbarItem parent class; DesktopToolbar, DesktopToolbarItem classes.