Click Here!
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


Chapter 5
Visual Basic Menus

If you need an immediate solution to:
Using The Visual Basic Application Wizard To Set Up Your Menus
What Item Goes In What Menu?
Adding A Menu To A Form
Modifying And Deleting Menu Items
Adding A Menu Separator
Adding Access Characters
Adding Shortcut Keys
Creating Submenus
Creating Immediate (“Bang”) Menus
Using The Visual Basic Predefined Menus
Adding A Checkmark To A Menu Item
Disabling (Graying Out) Menu Items
Handling MDI Form And MDI Child Menus
Adding A List Of Open Windows To An MDI Form’s Window Menu
Making Menus And Menu Items Visible Or Invisible
Creating And Displaying Pop-Up Menus
Adding And Deleting Menu Items At Runtime
Adding Bitmaps To Menus
Using The Registry To Store A Most Recently Used (MRU) Files List

In Depth

Everyone who uses Windows knows about menus—they’re those clever controls that hide away lists of items until you want to make a selection, like the Visual Basic File menu, which appears in Figure 5.1. And, in fact, that’s the design philosophy behind menus: rather than presenting the user with all possible controls at once, menus hide their items until needed. Imagine a program with 50 buttons all over it—Save File, Save File As, Insert Object, Paste Special, and so on—you’d hardly have space for anything else. That’s why menus are so popular: they present their controls in drop-down windows, ready to use when needed.


Figure 5.1  The Visual Basic File menu.

In this chapter, we’re going to take a look at using menus in Visual Basic. We’ll start with an overview of designing your menu system, including some considerations that Microsoft has developed. Then we’ll go to this chapter’s Immediate Solutions, seeing how to use the Visual Basic Menu Editor to create and modify menus. We’ll also see how to modify menus and the items they include from code, when a program is running. And, of course, we’ll see some special topics, like how to create a Most Recently Used (MRU) list of files and how to use Windows functions to add bitmaps to menu items.

We’ll start our overview on Visual Basic menus now by taking a look at the parts of a menu.

Menu Design Considerations

Every Windows programmer is familiar with the parts of a menu; for reference, they appear in Figure 5.1. The menu names in a program appear in the menu bar—usually just under the title bar—and when the user selects a menu, that menu opens, like the File menu in Figure 5.1.

Each menu usually contains items arranged in a vertical list. These items are often grouped into functional groups with menu separators, or thin horizontal rules, as shown in Figure 5.1. When the user selects a menu item (from the keyboard or with the mouse), that item appears highlighted; pressing Enter or releasing the mouse button opens that item.

Menu items can also be disabled (also called “grayed out”), as shown in Figure 5.1. A disabled item is not accessible to the user and does nothing if selected.


TIP:  If your program presents the user with a lot of disabled menu items, the user may feel locked out and frustrated. To avoid such situations, many programs add or remove menu items from menus at runtime, and we’ll see how to do that in this chapter.

Access Characters And Shortcuts

Ideally, each item should have a unique access character for users who choose commands with keyboards. The user reaches the menu or menu item by pressing Alt key and the access character. The access character should be the first letter of the menu title, unless another letter offers a stronger link; no two menus or menu items should use the same access character.

Shortcuts are also useful to the user; these keys are faster than access characters in that the user only needs to enter a shortcut to execute the corresponding menu item. For example, the New Project shortcut in Figure 5.1 is Ctrl+N.

Note also that an ellipsis (…) should follow names of menu items that display a dialog box (Save As…, Preferences…, etc.) when selected. In addition, if you have menus in the menu bar that execute a command immediately instead of opening a menu, you should append an exclamation point to the menu’s name, such as Collate!

Designing Your Menus

A popular aspect of Windows is that it gives the user a common interface, no matter what program they’re using, and users have come to expect that. In fact, if it’s hard to learn a new, nonstandard Windows program, the user may well turn to a Windows-compliant alternative, so it’s a good idea to stick with the Windows standards.

Most programs have a File menu first (at left) in the menu bar, followed by other menus, like a View menu, a Tools menu, and so on, followed by a Help menu, which usually appears last (and often at the extreme right in the menu bar). Users expect to find certain standard items in particular menus; for a list of these items, see “What Item Goes In What Menu?” in this chapter.

Microsoft recommends that you keep your menu item names short. For one thing, if you want to release your application internationally, the length of words tends to increase approximately 30 percent in foreign versions, and you may not have enough space to list all of your menu items. Microsoft also recommends that you use the mnu prefix in code for menus, like mnuFile, and menu items, like mnuFileOpen.

That completes our overview—it’s time to turn to the Immediate Solutions.

Immediate Solutions

Using The Visual Basic Application Wizard To Set Up Your Menus

Probably the easiest way to get a substantial menu system going in your program is to design that program with the Visual Basic Application Wizard. The menu-designing window that appears when you build an application with the Application Wizard appears in Figure 5.2.


Figure 5.2  Using the Application Wizard to design a menu system.

You can arrange, add, or remove menu items with the click of a mouse. The Application Wizard isn’t for everyone, but it can create a very complete menu system, as shown in Figure 5.3, where the File menu in the created application is open.


Figure 5.3  An Application Wizard—designed program’s menu system.


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.