![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
Adding Menus To Your Visual Basic AppsOne of the many features that most Windows applications have in common is a menu system. Visual Basics Menu Editor makes adding menus to your programs a snapand these menus are every bit as functional as the ones you see in any Windows program. You can add menus to any Visual Basic form; in a multiple-form program, each form can have its own menus. A menu is just another control, and like other controls, it has properties and responds to events. Because of the special requirements of menus, however, you must design a menu and set its properties with the Menu Editor. To start the Menu Editor (shown in Figure 11.2), display a form and press Ctrl+E or select Menu Editor from the Tools menu. You can also click on the Menu Editor button on the toolbar. Rather than bore you with a long-winded description of how the editor works, Ill walk you through the creation of the menus for our Baby Editor. Once we have completed that, youll know most of what there is to know about the Menu Editor and menu design. The rest I can fill in quickly and easily. Creating The Text Editors MenuWhat will our editor need in the way of menu commands? To keep the project simple, well create only two menus: a File menu and an Edit menu. The File menu will contain the New, Open, Save, Save As, and Exit commands. The Edit menu will contain the Copy, Cut, Paste, and Font commands. Lets get to work.
Display the projects form, then press Ctrl+E or select Tools|Menu Editor to display the Menu Editor. Because this form does not yet have a menu, the editor is blank. We will start by adding the first menu command to display on the menu bar. Because were following Windows conventions, this will be the File menu. In the Caption box, enter &File and youll see the menu caption appear in the large box at the bottom of the dialog box. Next, tab to the Name box and enter mnuFile, then click on the Next button. The highlight will move down a line in the menu outline, and the Text Boxes will be cleared, ready for you to enter the next menu item. First, let me point out two things:
Now, on to the next menu item. Enter &New in the Caption box and mnuFileNew in the Name box. Before clicking on the Next button, however, click on the right arrow button. Youll see the New captionnow displayed with an ellipsis in front of itmove over in the outline box. Essentially, weve made the New command subsidiary to the File command. In other words, New will appear as an item on the File menu, not as a separate menu item on the menu bar. Now click on Next. The new menu item (which is currently blank) is inserted at the same level as the item immediately preceding it (in this case, the New command). Enter &Open as the caption and mnuFileOpen as the name for this menu item. Open the Shortcut Key list and scroll down, selecting Ctrl+O to specify that the Ctrl+O key combination will be the shortcut for the File|Open command. Notice that Ctrl+O is displayed in the menu outline next to the Open caption. Add the remaining two commands to the File menu:
At this point, your Menu Editor should look like Figure 11.3. The next item we need to add to the File menu is not a menu command at all, but rather a separator a horizontal line separating one section of the menu from another. To add a separator, create a menu item with a caption consisting of just a single dash, or hyphen. Because all menu items must be named, well assign the name mnuFileSeparator to this item. After clicking on Next, add the last item on the File menu, using the caption E&xit and the name mnuFileExit.
After entering the Exit command and clicking on Next, you are ready to start with the Edit menu. At this point, any entry you make will be subsidiary to the File menu. Because we want Edit to be a top-level menu, you need to click on the left arrow button to move up one level on the outline. Assign the caption &Edit and the name mnuEdit to this menu item, then click on Next. Click on the right arrow to move down one level on the outline, and add the commands shown in Table 11.1 to the Edit menu.
Thats itthe menu is finished. Your Menu Editor will look like the one shown in Figure 11.4. Click on OK to close the Menu Editor and return to the form. You will see the menus on the form during design and when the program runs. You can open the menus and select commandsalthough nothing happens, because we havent written event code for the menu commands yet. We will be creating the event procedures later. Before we continue creating the project, lets go over the other Menu Editor commands. Even though you dont need them for this project, you will someday.
|
![]() |
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. Read EarthWeb's privacy statement. |