|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
Adding Toolbars To FormsFor some reason, adding toolbars to forms isnt covered in a lot of Visual Basic books. However, users have come to expect toolbars in more complex programs, and well see how to add them here. Toolbars provide buttons that correspond to menu items and give the user an easy way to select the commands those items correspond to. Adding A Toolbar With The Application Wizard The easiest way to design a toolbar and add it to a program is with the Application Wizard. When you create a new application using the Application Wizard, it lets you design the toolbar, as shown in Figure 4.5.
This is a great way to put a toolbar in a program, because the support is already there for all these buttons by default. When you create the program, heres how it handles the buttons in the toolbar, with a Select Case statement that looks at the buttons Key value:
Private Sub tbToolBar_ButtonClick(ByVal Button As ComctlLib.Button)
On Error Resume Next
Select Case Button.Key
Case "New"
LoadNewDoc
Case "Open"
mnuFileOpen_Click
Case "Save"
mnuFileSave_Click
Case "Print"
mnuFilePrint_Click
Case "Copy"
mnuEditCopy_Click
Case "Cut"
mnuEditCut_Click
Case "Paste"
mnuEditPaste_Click
Case "Bold"
ActiveForm.rtfText.SelBold = Not ActiveForm.rtfText.SelBold
Button.Value = IIf(ActiveForm.rtfText.SelBold, tbrPressed,_
tbrUnpressed)
Case "Italic"
ActiveForm.rtfText.SelItalic = Not ActiveForm.rtfText._
SelItalic
Button.Value = IIf(ActiveForm.rtfText.SelItalic, tbrPressed,_
tbrUnpressed)
Case "Underline"
ActiveForm.rtfText.SelUnderline = Not _
ActiveForm.rtfText.SelUnderline
Button.Value = IIf(ActiveForm.rtfText.SelUnderline,_
tbrPressed,tbrUnpressed)
Case "Align Left"
ActiveForm.rtfText.SelAlignment = rtfLeft
Case "Align Right"
ActiveForm.rtfText.SelAlignment = rtfRight
Case "Center"
ActiveForm.rtfText.SelAlignment = rtfCenter
End Select
End Sub
Adding A Toolbar To A Program Yourself You can also add toolbars to already-existing programs; just follow these steps:
And thats itnow weve added a toolbar to a program; when the user clicks a key in the toolbar, our program will handle it. The result appears in Figure 4.7.
|
|
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. |