|
|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
Thats all we neednow run the program, as shown in Figure 15.16.
When users make a selection with the combo box, we display a message box letting them know what theyve selected. Our combo box toolbar example is a success. The code for this example appears in the combotoolbar folder on this books accompanying CD-ROM. Setting Toolbar Button Tool TipsGiving toolbar buttons tool tips (those small yellow windows that display explanatory text when the mouse cursor rests on the underlying control) is an easy process. All you need to do to give a button a tool tip is to set its ToolTipText property. To set the ToolTipText property, right-click the toolbar and select the Properties item in the menu that opens. Click the Buttons tab and select the button you want to add the tool tip to. Place the tool tip text in the box labeled ToolTipText, as shown in Figure 15.17. Finally, close the property pages by clicking on OK. Now when you run the program, the button displays a tool tip, as shown in Figure 15.18.
Letting The User Customize The ToolbarThe Testing Department has sent you a memo. Some users of your new program, SuperDuperTextPro, want the Save button at left in the toolbar, but other users want the Create New Document button there. What can we do? You can let the user customize the toolbar. Just set the AllowCustomize property to True (the default). When the user double-clicks the toolbar, the Customize Toolbar dialog box appears, as shown in Figure 15.19. Users can customize the toolbar as they like using that dialog box.
Adding Toolbar Buttons At RuntimeHow do you add buttons to a toolbar at runtime? Its possible to add menu items to menus, so it should be possible to add buttons to toolbars. It is. To add a new button when the user clicks a button, we start by declaring a new Button object:
Private Sub Command1_Click()
Dim Button1 As Button
...
End Sub
Next, we add a new button to the toolbars Buttons collection, which is how it stores its buttons internally. As with all collections, the Buttons collection has an Add method, and we use it here:
Private Sub Command1_Click()
Dim Button1 As Button
Set Button1 = Toolbar1.Buttons.Add()
...
End Sub
Now were free to set the buttons style. Here, we make it a standard button by setting its Style property to tbrDefault (other options include tbrButtonGroup, tbrSeparator, tbrCheck, tbrPlaceHolder, and tbrDropDown):
Private Sub Command1_Click()
Dim Button1 As Button
Set Button1 = Toolbar1.Buttons.Add()
Button1.Style = tbrDefault
...
End Sub
We can also give the new button a caption:
Private Sub Command1_Click()
Dim Button1 As Button
Set Button1 = Toolbar1.Buttons.Add()
Button1.Style = tbrDefault
Button1.Caption = "New button"
...
End Sub
Finally, we give the new button a tool tip:
Private Sub Command1_Click()
Dim Button1 As Button
Set Button1 = Toolbar1.Buttons.Add()
Button1.Style = tbrDefault
Button1.Caption = "New button"
Button1.ToolTipText = "New button"
End Sub
And thats itthe new button is active. Its been added to the Buttons collection of the toolbar control, which means it has its own Index value. That Index value will be passed to the ButtonClick handler, and we can make use of the index this way (you can also set a buttons key text from code by setting its Key property):
Private Sub Toolbar1_ButtonClick(ByVal Button As ComctlLib.Button)
MsgBox "You clicked button " & Button.Index
End Sub
Adding A Status Bar To A ProgramThe Testing Department is calling again. Your new SuperDuperDataCrunch program looks good, but what about the status bar? You ask, what status bar? Exactly, they say. How can you add a status bar to your program? You could design the program with the Visual Basic Application Wizard, which automatically adds a status bar (see Adding A Toolbar To A Form earlier in this chapter for more information). However, most programmers will want to add their own status bar to their programs, and you create a status bar by adding a status bar control to a form. Heres how that works:
This adds the Status Bar Control tool to the Visual Basic toolbox, as shown in Figure 15.2. To place a status bar in your form, just double-click the Status Bar Control. Now youve got a new status barbut how do you align it at the top of the window and display text in it? See the next couple of topics in this chapter. Aligning Status Bars In A FormNow that youve added a status bar to your form, where does it go? By default, it aligns itself with the bottom of the client area of the form. You can set the alignment of the status bar with its Align property, which can take these values:
Adding Panels To A Status BarNow that youve added a status bar to your program, its time to take the next step: adding panels to the status bar. The text in a status bar is displayed in those panels. A status bar control has a Panels collection, and you add the panels you want to that collection. To do that at design time, follow these steps:
|
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. |