Поделиться через


ToolBar Control Overview (Windows Forms)

Note

The ToolStrip control replaces and adds functionality to the ToolBar control; however, the ToolBar control is retained for both backward compatibility and future use, if you choose.

The Windows Forms ToolBar control is used on forms as a control bar that displays a row of drop-down menus and bitmapped buttons that activate commands. Thus, clicking a toolbar button can be an equivalent to choosing a menu command. The buttons can be configured to appear and behave as pushbuttons, drop-down menus, or separators. Typically, a toolbar contains buttons and menus that correspond 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 usually "docked" along the top of its parent window, but it can also be docked to any side of the window. A toolbar can display tooltips when the user points the mouse pointer at a toolbar button. A ToolTip is a small pop-up window that briefly describes the button or menu's purpose. To display ToolTips, the ShowToolTips property must be set to true.

Note

Certain applications feature controls very similar to the toolbar that have the ability to "float" above the application window and be repositioned. The Windows Forms ToolBar control is not able to do these actions.

When the Appearance property is set to Normal, the toolbar buttons appear raised and three-dimensional. You can set the Appearance property of the toolbar to Flat to give the toolbar and its buttons a flat appearance. When the mouse pointer moves over a flat button, the button's appearance changes to three-dimensional. Toolbar buttons can be divided into logical groups by using separators. A separator is a toolbar button with the Style property set to Separator. It appears as empty space on the toolbar. When the toolbar has a flat appearance, button separators appear as lines rather than spaces between the buttons.

The ToolBar control allows you to create toolbars by adding Button objects to a Buttons collection. You can use the Collection Editor to add buttons to a ToolBar control; each Button object should have text or an image assigned, although you can assign both. The image is supplied by an associated ImageList component. At run time, you can add or remove buttons from the ToolBar.ToolBarButtonCollection using the Add and Remove methods. To program the buttons of a ToolBar, add code to the ButtonClick events of the ToolBar, using the Button property of the ToolBarButtonClickEventArgs class to determine which button was clicked.

See Also

Tasks

How to: Add Buttons to a ToolBar Control

How to: Define an Icon for a ToolBar Button

How to: Trigger Menu Events for Toolbar Buttons

Reference

ToolBar

Other Resources

ToolBar Control (Windows Forms)