|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
Publication Date: 08/01/98
Chapter 15 Toolbars, Status Bars, Progress Bars, And Coolbars
- If you need an immediate solution to:
- Adding A Toolbar To A Form
- Aligning Toolbars In A Form
- Adding Buttons To A Toolbar
- Handling Toolbar Buttons Clicks
- Connecting Toolbar Buttons To Menu Items
- Adding Separators To A Toolbar
- Adding Images To Toolbar Buttons
- Adding Check (Toggle) Buttons To A Toolbar
- Creating Button Groups In A Toolbar
- Adding Combo Boxes And Other Controls To A Toolbar
- Setting Toolbar Button Tool Tips
- Letting The User Customize The Toolbar
- Adding Toolbar Buttons At Runtime
- Adding A Status Bar To A Program
- Aligning Status Bars In A Form
- Adding Panels To A Status Bar
- Displaying Text In A Status Bar
- Displaying Time, Dates, And Key States In A Status Bar
- Customizing A Status Bar Panels Appearance
- Displaying Images In A Status Bar
- Handling Panel Clicks
- Adding New Panels To A Status Bar At Runtime
- Creating Simple Status Bars
- Adding A Progress Bar To A Form
- Using A Progress Bar
- Adding A Coolbar To A Form
- Aligning Coolbars In A Form
- Adding Bands To A Coolbar
- Adding Controls To Coolbar Bands
- Handling Coolbar Control Events
In Depth
In this chapter, were going to take a look at the bar controls: toolbars, status bars, progress bars, and coolbars. All these controls have their uses in Visual Basic programs, and users are coming to expect them more and more. Well start with an overview of these controls.
Toolbars
Every Windows user knows about toolbars: theyre those bars at the top of a window (although they can appear other places as well) that are filled with buttons and, sometimes, other controls like combo bars.
Often, a toolbar contains buttons that correspond to items in an applications menu, providing an easy interface for the user to reach frequently used functions and commands. In this way, toolbars can make life a lot easier for the user. The user can also customize toolbars: double-clicking a toolbar at runtime opens the Customize Toolbar dialog box, which allows the user to hide, display, or rearrange toolbar buttons.
You create a toolbar by adding a toolbar control to a form, and to do that, you select the Project|Components menu item, then click the Controls tab in the Components dialog box, select the Microsoft Windows Common Controls item, and click on OK to close the Components dialog box. This adds the Toolbar Control tool to the Visual Basic toolbox, as shown in Figure 15.1; the Toolbar tool is the twelfth tool down on the left.
Figure 15.1 The Toolbar Control tool.
To add buttons to a toolbar, you add Button objects to its Buttons collection, usually by working with the toolbars property pages. Each button can have text and/or an image, (supplied by an associated ImageList control). Set text with the Caption property and an image with the Image property for each Button object. At runtime, you can add or remove buttons from the Buttons collection using Add and Remove methods.
Status Bars
Status bars appear at the bottom of windows and usually hold several panels in which you can display text. The status bar is there to give feedback to the user on program operation, as well as other items like time of day or key states (such as the Caps Lock or the Ins key). Although status bars usually display text in panels, there is a simple status bar style that makes the status bar function as one long panel, as well see.
Status bars are built around the Panels collection, which holds the panels in the status bar. Up to 16 Panel objects can be contained in the collection. Each object can display an image and text, as shown later in this chapter. You can change the text, images, or widths of any Panel object, using its Text, Picture, and Width properties. To add Panel objects at design time, right-click the status bar, and click Properties to display the Property Pages dialog box. (Well cover the procedure in more detail later in the chapter.)
You add the Status Bar Control tool to the toolbox by following the same steps to add the Toolbar Control tool, because the status bar control is also part of the Microsoft Windows common controls. The Status Bar Control tool is the twelfth tool down on the right in Figure 15.2.
Figure 15.2 The Status Bar Control tool.
Progress Bars
Progress bars give the user some visual feedback on whats happening during a time-consuming operation. They present the user with a color bar that grows in the control to show how the operation is proceeding, usually from 0 to 100 percent. You can use a progress bar when an operation will take some time to finish. The progress bars Value property (not available at design time) determines how much of the control has been filled. The Min and Max properties set the limits of the control.
You add the Progress Bar Control tool to the toolbox by following the same steps to add the toolbar tool, because the progress bar control is also part of the Microsoft Windows common controls. The Progress Bar Control tool is the thirteenth tool down on the left in Figure 15.3.
Figure 15.3 The Progress Bar Control and the Coolbar Control tools.
Coolbars
Coolbars were first introduced in the Microsoft Internet Explorer, and they are toolbars that present controls in bands. Users can adjust these bands by dragging a gripper, which appears at left in a band. In this way, users can configure the coolbar by sliding the bands around as they want. One popular use of coolbars is to display toolbars in the bands of that coolbar, allowing users to move those toolbars around as they want.
The Coolbar Control tool is on the bottom, at left, in the Visual Basic toolbox in Figure 15.3. These controls can act just as toolbars do, as well see.
Thats it for the overviewits time to turn to the Immediate Solutions.
Immediate Solutions
Adding A Toolbar To A Form
The Testing Department is calling again. Your program, SuperDuperTextPro, is wonderfulbut what about putting in a toolbar? That would make things easier for the programs users, because they could click buttons in the toolbar instead of having to open menu items. So how do you add a toolbar to a form?
|