home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
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

Bookmark It

Search this book:
 
Previous Table of Contents Next


What Item Goes In What Menu?

The Testing Department gives you a call to ask why the Paste item in your new application is in the View menu. You ask if they had a different menu in mind, and they mention something about the Edit menu. How can you avoid such calls? With the following lists.

Users expect to find certain standard items in certain menus if your program is going to support those items. To start us off, here’s the kind of item you might find in the File menu (note that not all programs will use all these menus):

  New
  Open
  Close
  Close All
  Save
  Save As
  Save All
  Properties
  Templates
  Page Setup
  Print Preview
  Print
  Print Using
  Send
  Update
  Exit


TIP:  Even in programs that don’t handle files, it’s not uncommon to see a File menu for one reason—that’s where the user expects the Exit item. Don’t forget to add an Exit item to your menu system (you can end a Visual Basic program using the End statement, so this menu item is easy to implement).

The Edit menu usually holds items like these:

  Undo
  Redo
  Cut
  Copy
  Paste
  Paste Using
  Paste Special
  Clear
  Select All
  Find
  Replace
  Bookmark
  Insert Object (unless you have a separate Insert menu)

The View menu has items like these:

  Toolbar
  Status Bar
  Refresh
  Options

The Window menu has items like these:

  New Window
  Cascade
  Tile Windows
  Arrange All
  Split
  List Of Windows

The Help menu has items like these:

  Help
  Help Index
  Help Table of Contents
  Search for Help On
  Web Support
  About

Adding A Menu To A Form

The design process is complete—it’s time to start adding menus to your new program. But when you sit down and start looking for the Menu tool in the toolbox, you find that there isn’t one. Just how do you add a menu to a form?

You use the Visual Basic Menu Editor. You’ll get a basic introduction to the Menu Editor here, and we’ll use it throughout this chapter. To add a menu to a form, select that form (that is, click on it), and open the Menu Editor by selecting the Menu Editor in the Tools menu. Or, you can select its icon in the toolbar (which has the tool tip “Menu Editor”). The Visual Basic Menu Editor appears in Figure 5.4.


Figure 5.4  The Visual Basic Menu Editor.

Creating A New Menu

To create a new menu, you only have to provide two essential items: the caption of the menu and its name. The Caption property holds the title of the menu, such as File, and the Name property holds the name you’ll use for that menu in code, such as mnuFile.

Fill in the Caption and Name properties for your new menu now. Congratulations—you’ve created a new menu. Now it’s time to add items to the new menu.

Creating A New Menu Item

We can add a new menu item, say, New, to the File menu we’ve just created. To do so, click the Next button in the Menu Editor, moving the highlighted bar in the box at the bottom of the Menu Editor down one line. If you just entered new Caption and Name values and left it at that, you’d create a new menu, not a new menu item. So click the right-pointing arrow button in the Menu Editor now to indent the next item four spaces in the box at the bottom of the Menu Editor. Now enter the Caption (“New”) and Name, (“mnuFileNew”) values for the new menu item.

The menu item you’ve just created appears in the Menu Editor below the File menu item and indented, like this:

File
....New

This means that we now have a File menu with one item in it—New.

That’s how your menu system is displayed in the Menu Editor: as a series of indented items. For example, here’s how a File menu with New and Open items, followed by an Edit menu with three items, Cut, Copy, and Paste, would look in the Menu Editor:

File
....New
...Open
Edit
....Cut
....Copy
....Paste

Here’s how to create a new menu system in the Menu Editor, step-by-step:

1.  Enter the first menu’s Caption and Name.
2.  Click the Next button (or press Enter).
3.  Click the right arrow to indent one level, making this next entry a menu item.
4.  Enter the menu item’s Caption and Name.
5.  Click the Next button (or press Enter).
6.  Repeat Steps 4 and 5 for all the items in the first menu.
7.  Click the Next button (or press Enter).
8.  Click the left arrow to outdent, making this next entry a menu.
9.  Enter the next menu’s Caption and Name.
10.  Click the right arrow to indent one level, making this next entry a menu item.
11.  Repeat Steps 4 and 5 for the items in this new menu.
12.  Repeat Steps 7 through 11 for the rest of the menus in the program.
13.  Click on OK to close the Menu Editor.
14.  Edit the code.

You edit the code for menu items just as you do for other controls—click the menu item in the form under design (opening the item’s menu if necessary). This opens the menu item’s event handler, like this:

Private Sub mnuFileNew_Click()

End Sub

Just add the code you want to execute when the user chooses this menu item to the event handler procedure:

Private Sub mnuFileNew_Click()
    LoadNewDoc
End Sub

And that’s it—now you’ve added a menu system to your program.

Modifying And Deleting Menu Items

You think the program is perfect, but the users are complaining that they don’t like having the Save As item in the Edit menu and want to move it to the File menu. Is that possible?

Yes, using the Menu Editor. You can rearrange, add, or remove items in your menu with the Menu Editor, so open that tool now (as shown in Figure 5.4).

Inserting Or Deleting Items In A Menu System

To add a new item to a menu, or a new menu to the menu system, select an item in the Menu Editor, and click the Insert button. This inserts a new, empty entry into the menu just before the item you selected:

File
....New
....Open
...
Edit
....Cut
....Copy
....Paste


Previous Table of Contents Next


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.