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


Now just enter the new item’s Caption and Name properties, and you’re all set.

To remove a menu or menu item, just select that menu or item and click the Delete button.

Rearranging Items In A Menu System

You can use the four arrow buttons in the Menu Editor to move items up and down, as well as indent or outdent (that is, remove one level of indenting) menu items. Here’s what the arrows do:

  Right arrow— Indents a menu item.
  Left arrow— Outdents a menu item.
  Up arrow— Moves the currently selected item up one level.
  Down arrow— Moves the currently selected item down one level.

For example, to move the Save As item from the Edit menu to the File menu, just select that item and keep clicking the up arrow button until the Save As item is positioned as you want it in the File menu.

Adding A Menu Separator

Menus themselves allow you ways to group commands by function (File, Edit, and so on). Often within a menu, however, it helps the user to group menu items by function (Print, Print Preview, Page Setup, and so on). You do that with menu separators.

A menu separator is a horizontal rule that really only has one purpose—to divide menu items into groups (refer back to Figure 5.1). And using the Menu Editor, you can add separators to your menus.

To add a menu separator, select an item in the Menu Editor and click Insert to create a new item just before the item you selected. To make this new item a menu separator, just give use a hyphen (-) for its Caption property. You must give all menu items a name—even if they don’t do anything—so give it a dummy Name property value as well, such as mnuSeparator.

When you run the program, you’ll see the menu separators in place, as in the menu in Figure 5.5. Now we’re adding menu item separators to our menus.


Figure 5.5  A menu with menu separators.

Adding Access Characters

The Testing Department’s calling again: They like the menus you’ve added to your program, but there’s the keyboard access issue. Theoretically, they say, users should be able to use the keyboard for everything.

It’s time to add access characters to your program. When the user presses the Alt key and an access character, the menu item corresponding to that access character is selected. How do you associate an access character with a menu or menu item? It’s easy—just place an ampersand (&) in front of the character you want to make into the access character in that menu or item’s caption.

For example, if you had this menu system

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

you could make a letter in all menus or menu items into access characters by placing an ampersand in front of it:

&File
....&New
....&Open
&Edit
....&Cut
....C&opy
....&Paste

Avoiding Access Character Duplication

Note in the previous example that we have two items—Cut and Copy—in the Edit menu that begin with “C”. That’s a problem, because an access character must be unique at its level (where the level is the menu bar for menus and a menu for menu items). To avoid confusion (both to the user and to Visual Basic), we make “o”, the second letter in Copy, the access character for that item.

The result of adding access characters to your menus at design time appears in the Menu Editor in Figure 5.6. At runtime, access characters appear underlined in menus, as shown in Figure 5.7.


Figure 5.6  Adding access characters.


Figure 5.7  Access characters are underlined.

To use an access key, users first open the menu in which the item they want to select appears (possibly using an access key, like Alt+F for the File menu), then they press the Alt key and the access key.

Adding Shortcut Keys

One of the most powerful aspects of menus are shortcut keys—single keys or key combinations that let the user execute a menu command immediately (without having to open the menu the command is in, as you must do with access keys). You usually use function keys (although many PCs now go up to F16, it’s best to limit yourself to F1 through F10) or Ctrl key combinations for shortcut keys. For example, the standard shortcut key for Select All is Ctrl+A, and entering that shortcut selects all the text in a document.

Giving a menu item a shortcut key is very easy in the Menu Editor. Just open the Menu Editor, select the item you want to give a shortcut key to (such as the File menu’s New item in Figure 5.8) and select the shortcut key you want to use in the Menu Editor box labeled Shortcut. (Note that to open the Menu Editor, the form you’re designing must be the active window in Visual Basic, not the code window.) In Figure 5.8, we give the New item the shortcut Ctrl+N.


Figure 5.8  Setting a shortcut key.

That’s all it takes—now run the program, as shown in Figure 5.9. You can see the Ctrl+N at the right in the menu item named New—we’ve installed our menu shortcut.


Figure 5.9  Shortcut key in a program’s menu.

Shortcut Key Standards

Windows conventions now include a set of standard shortcut keys that are supposed to apply across most Windows applications. Here are the most common shortcut keys (be very careful when using these key combinations for other purposes; your users may expect the standard response):

  Ctrl+A—Select All
  Ctrl+B—Bold
  Ctrl+C—Copy
  Ctrl+F—Find
  Ctrl+G—Go To
  Ctrl+H—Replace
  Ctrl+I—Italic
  Ctrl+J—Justify
  Ctrl+N—New
  Ctrl+O—Open
  Ctrl+P—Print
  Ctrl+Q—Quit
  Ctrl+S—Save
  Ctrl+U—Underline
  Ctrl+V—Paste
  Ctrl+W—Close
  Ctrl+X—Cut
  Ctrl+Z—Undo
  F1—Help

Creating Submenus

The email is in—and it’s more praise for your program, AmazingWingDings (Deluxe version). It’s gratifying to read the great reviews—but one user asks if you couldn’t place the Red, Green, and Blue color selections in the Edit menu into a submenu. What are submenus, and how can you create them?


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.