The ToolBar
The ToolBar control represents a strip of buttons that gives access to various features in an application. Conceptually, toolbars play the same role as menus. The difference is that toolbars are only a single level deep and are often restricted to the most important functions. Menus use a multilayered hierarchical structure that provides a single point of access to all features in an application.
Toolbar buttons can include text and variable-size pictures. You can layer several toolbars on a form, and attach drop-down menus to a button. Figure 6-10 shows some common toolbar button styles.

Figure 6-10: Toolbar styles
Unfortunately, .NET does not currently provide any way to create a "cool bar," the snap-in toolbar strip used in applications like Microsoft Word that can include other controls (like drop-down list boxes) and can be manually detached by the user into floating tool windows. This is likely to change with future .NET framework releases (or third-party development). Until then, you can start to create your own using the information in Chapter 8, or use ActiveX interop with the components provided with Visual Studio 6.
Most of the ToolBar properties are appearance-related (see Table 6-9).
Table 6-9: Appearance-related ToolBar Properties
MemberDescription
AppearanceToolBarAppearance.Normal makes buttons appear three-dimensional, like command buttons. ToolBarAppearance.Flat gives toolbar buttons a more modern look. They begin flat, and appear raised when the mouse moves over them. Separators on a toolbar with the Appearance property set to Flat appear as etched lines rather than spaces.
AutoSizeWhen true (the default), the toolbar sizes itself to accommodate the toolbar buttons, based on the button size, the number of buttons, and the DockStyle of the toolbar.
BorderStyleWhen set to BorderStyle.Fixed3D the toolbar has a sunken, three-dimensional appearance. With BorderStyle.FixedSingle, the toolbar has a flat thin border around it.
ButtonSizeA size structure specifying a size for each button. If a size is not set, the default is used (24 pixels by 22 pixels), or a size is assigned that is large enough to accommodate the image and text for the button.
DividerThe default, true, displays a raised edge along the top of the toolbar to help separate it (typically from a menu).
DropDownArrowsWhen false, no down arrow is shown for toolbars that have linked menus (although the drop-down menu is still shown when the button is clicked). When set to true, drop-down buttons provide an arrow that the user must click to show the menu.
ImageListThe attached ImageList used for button pictures.
ShowToolTipsIf set to true, you can set the ToolTipText property of each button object to assign a tooltip (the ToolTipProvider extender control is not used).
TextAlignSets the alignment for the button text on the toolbar. The options are underneath the image or to the right of the image.
WrappableIf true (the default), and the toolbar becomes too small to display all the buttons on the same line, the toolbar is broken into additional lines, with the breaks occurring at the separators.
The most important part of a ToolBar is its Buttons property, which contains the collection of button controls. As with the TreeView and ListView, you can add individual ToolBarButton objects using a special designer in Visual Studio.NET (shown in Figure 6-11), or through code.

Figure 6-11: Toolbar designer
Each ToolBarButton provides its own set of important properties, as listed in Table 6-10.
Table 6-10: ToolBarButton Properties
MemberDescription
DropDownMenuReferences a ContextMenu object that contains the dropdown menu that is shown for the button. You also must set the Style for the button to DropDown.
Enabled and VisibleWhen not enabled, the button appears dimmed (greyed out) and does not respond to button clicks. Buttons that are not visible do not appear in the toolbar.
ImageIndexAssigns a picture from the ImageList bound to the toolbar.
PartialPush and PushedYou can set Pushed to true to indent a button. This is typically used with toggle buttons, which can be pushed and unpushed by the user. PartialPush shows a dimmed pushed button, which is meant to show a combination of the pushed and unpushed states (for example, a Bold button might appear partially pushed if the current selection has both bold and normal text).
StyleConfigures the type of button from the ToolBarButtonStyle enumeration. You can use PushButton for the standard button, Separator for an etched line between buttons (or just a space, depending on the ToolBar.Appearance setting), or ToggleButton for a button that appears sunken when clicked and retains the sunken appearance until clicked again.
TagAllows you to attach other information to a ToolBarButton. This property needs to be specifically added to this class by the .NET framework, as ToolBarButton does not inherit from the base Control class.
TextThe text that appears on the button face.
ToolTipTextThe tooltip that is shown for the button, if the ToolBar.ShowToolTips property is true.
Reacting to button clicks is not much different than reacting to a menu. You can handle each ToolBarButton.Click event separately, or you can handle them with the same event handler, and inspect the object reference to determine which button was clicked.