Visual Basic: Windows Controls
A Toolbar control contains a collection of Button objects used to create a toolbar that is associated with an application.
Typically, a toolbar contains buttons that correspond to items in an application's menu, providing a graphic interface for the user to access an application's most frequently used functions and commands.
The Toolbar control allows you to create toolbars by adding Button objects to a Buttons collection. Each Button object can have optional text or an image, or both, supplied by an associated ImageList control. You can display an image on a button with the Image property, or display text with the Caption property, or both, for each Button object. At design time, you can add Button objects to the control using the Properties Page of the Toolbar control. At run time, you can add or remove buttons from the Buttons collection using the Add and Remove methods.
To program the Toolbar, add code to the ButtonClick event to respond to the selected button. You can also determine the behavior and appearance of each Button object using the Style property. For example, if four buttons are assigned the ButtonGroup style, only one button can be pressed at any time and at least one button is always pressed.
You can create space for other controls on the toolbar by assigning a Button object the PlaceHolder style, then positioning a control over the placeholder. For example, to place a drop-down combo box on a toolbar at design time, add a Button object with the PlaceHolder style and size it as wide as a ComboBox control. Then place a ComboBox control on the placeholder.
Double clicking a toolbar at run time invokes the Customize Toolbar dialog box, which allows the user to hide, display, or rearrange toolbar buttons. To enable or disable the dialog box, use the AllowCustomize property. You can also invoke the Customize Toolbar dialog box using the Customize method. If you wish to save and restore the state of a toolbar, or allow the user to do so, two methods are provided: the SaveToolbar and RestoreToolbar methods. The Change event, generated when a toolbar is altered, is typically used to invoke the SaveToolbar method.
Note The Customize dialog box also includes a Help button. Use the HelpFile and HelpContextID properties to determine which (if any) help file is displayed when the end user clicks the Help button.
Usability is further enhanced by programming ToolTipText descriptions of each Button object. To display ToolTips, the ShowTips Property must be set to True. When the user invokes the Customize Toolbar dialog box, clicking a button causes a description of the button to be displayed in the dialog box; this description can be programmed by setting the Description property.
Distribution Note The Toolbar control is part of a group of ActiveX controls that are found in the MSCOMCTL.OCX file. To use the Toolbar control in your application, you must add the MSCOMCTL.OCX file to the project. When distributing your application, install the MSCOMCTL.OCX file in the user's Microsoft Windows System or System32 (on Windows NT platforms) folder. For more information on how to add an ActiveX control to a project, see "Loading ActiveX Controls," in the Component Tools Guide.