Using Toolbars
The AlterNET UI Toolbar control is used as a control bar that displays a row of drop-down menus and bitmapped buttons that activate commands. Thus, clicking a toolbar button is equivalent to choosing a menu command. You can configure toolbar buttons to appear and behave as push buttons, drop-down menus, or separators. Typically, a toolbar contains buttons and menus corresponding to items in an application's menu structure, providing quick access to an application's most frequently used functions and commands.
Working with the Toolbar Control
A Toolbar control is "docked" along the top of its parent window. Use the Toolbar property to specify a toolbar associated with the window.
The Toolbar control allows you to create toolbar items by adding ToolbarItem objects to a Items collection. Each ToolbarItem object should have Text or an Image assigned, although you can assign both. The image is supplied by an associated ImageSet component. At run time, you can add or remove buttons from the Items collection. To program the items of a Toolbar, add code to the Click events of the ToolbarItem to determine which toolbar item was clicked.
Using IsCheckable property, you can specify whether a ToolbarItem can be "checked" or "toggled". Use Checked property to tell the check state of such items.
Use DropDownMenu to specify a drop-down Menu for a ToolbarItem.
Set ToolbarItem.Text property to a minus ("-") value to use the item as a toolbar separator.
A toolbar can display tooltips when the user points the mouse pointer at a toolbar button. A ToolTip is a small pop-up window briefly describing the button or menu's purpose.
The following example shows how to use Toolbar component:
<Window>
<Window.Toolbar>
<Toolbar>
<ToolbarItem Text="Calendar" Image="embres:MenuSample.Resources.Icons.Small.Calendar16.png"
Click="ToolbarItem_Click" ToolTip="Calendar Toolbar Item" />
<ToolbarItem Text="-" />
<ToolbarItem Text="Pencil Toggle" Image="embres:MenuSample.Resources.Icons.Small.Pencil16.png"
Click="ToggleToolbarItem_Click"
ToolTip="Pencil Toolbar Item" IsCheckable="true" Name="checkableToolbarItem" />
<ToolbarItem Text="-" />
<ToolbarItem Text="Graph Drop Down" ToolTip="Graph Toolbar Item"
Image="embres:MenuSample.Resources.Icons.Small.LineGraph16.png" Click="ToolbarItem_Click">
<ToolbarItem.DropDownMenu>
<ContextMenu>
<MenuItem Text="_Open..." Name="openToolbarMenuItem" Click="ToolbarDropDownMenuItem_Click" />
<MenuItem Text="_Save..." Name="saveToolbarMenuItem" Click="ToolbarDropDownMenuItem_Click" />
<MenuItem Text="-" />
<MenuItem Text="E_xport..." Name="exportToolbarMenuItem" Click="ToolbarDropDownMenuItem_Click" />
</ContextMenu>
</ToolbarItem.DropDownMenu>
</ToolbarItem>
</Toolbar>
</Window.Toolbar>
</Window>
private void ToolbarItem_Click(object? sender, EventArgs e)
{
MessageBox.Show("Toolbar item clicked: " + ((ToolbarItem)sender!).Text);
}
private void ToggleToolbarItem_Click(object sender, EventArgs e)
{
var item = (ToolbarItem)sender;
MessageBox.Show($"Toggle toolbar item clicked: {item.Text}. Is checked: {item.Checked}");
}
private void ToolbarDropDownMenuItem_Click(object sender, EventArgs e)
{
var item = (MenuItem)sender;
MessageBox.Show($"Toolbar drop down menu item clicked: {item.Text.Replace("_", "")}.");
}