Adding and Modifying a Menu

If you want your application to provide a set of commands to users, menus offer a convenient and consistent way to group commands and an easy way for users to access them. The menu bar appears immediately below the title bar on the form and contains one or more menu titles. When you click a menu title (such as File), a menu containing a list of menu items appears. Menu items can include commands (such as New and Exit), separator bars, and submenu titles. Each menu item the user sees corresponds to a menu control property you define. Multiple menus can be added to one form.

To add a menu to your form

  1. Under WFC Controls in the Toolbox, double-click the MainMenu control.

Note   You can also select the MainMenu control and drag it onto your form.

The MainMenu control is inserted onto your form, and the default location for the first item on the menu bar is displayed. Two visual markers (Type Here) appear directly to the right and below to signify the next available editing location.

Note   By default, the MainMenu property for the form is set to MainMenu1.

  1. Type the name of your first menu caption in the default location text box. (For example, type File to add the File menu.)

    The menu caption is added to your menu, and the default location text box moves to the next menu caption location. Continue typing your menu captions until all your captions are complete.

Forms can have several menu items, such as File/Save and File/SaveAs, that change depending on the state of the application. Menus can be enabled or disabled, checked or unchecked, made visible or hidden using properties for each menu item.

If you want to change the main menu used by a form, you change the menu property for the form to a different menu name, for example, mainMenu2.

You can add access keys to your menu. Access keys provide a way for the user to access the menu using only the keyboard. An access key corresponds to an underlined letter on the menu.

To add access keys to a menu

  1. Click the menu caption in which you want to add an access key.

  2. Place the cursor immediately before the letter in the caption box that you want to be your access key letter and type an ampersand (&). For example, on the File menu, click File, place your cursor before the "F" in File, and then type an ampersand. You can also edit the caption title through the Text property for the menu item.

Shortcut keys add accessibility to your menus. A shortcut key is a keyboard combination, such as CTRL+C for copy, that invokes a particular command.

To add a shortcut key to a menu item

  1. Click to the immediate right of the menu item caption to which you want to add a shortcut key. A dropdown list appears.

  2. Select a key combination from the dropdown list.

    -or-

    In the Properties window, click the shortcut property and select a key combination.

To remove a shortcut key

  1. Select a menu item.

  2. Set the shortcut property to none.

At times, you may want to give users various commands that they can apply to the application. For example, there may be several available toolbars in an application. The user can select which toolbar will be displayed by clicking the toolbar name on the menu, and a check mark appears next to the toolbar name.

To enable check marks on a menu

  1. Select a menu item.

  2. Click to the immediate left of the menu item name. A checkbox apears.

    -or-

    In the Properties window, click the checked property.

To move a menu

  1. Select the desired menu item caption.

  2. Drag the menu caption to the new position.

    The menu caption moves and snaps to place. Other menu captions that are affected by this change are moved as appropriate.

Note   Moving top-level menu captions moves all submenus as well. Submenus are not displayed during the move.

To modify a menu caption

  1. Click the menu caption you want to modify.

  2. In the text box containing the menu caption, make any necessary changes.

Separator bars are used in menus to add a distinct line between groups of commands.

To create a menu separator bar

  1. Click the menu caption that is above the location where you want to add a separator bar.

  2. Press the HYPHEN (–) key and then press ENTER.

    A separator bar appears directly below your menu caption.

    -or-

    Click the right mouse button, and then click Insert Separator on the context menu.

Separator bars can be moved and deleted in the same manner as menu captions.

To delete a menu item from your form

Note   To delete the entire menu, select each menu caption and press DELETE, or click the MainMenu control you want to delete and press DELETE.

Confirmation on deletion occurs only on menu captions with submenus.

To edit the name associated with a menu item

  1. Click the right mouse button over a menu item.

  2. Click Edit Names to toggle the Edit Names mode for the menu.

  3. Click on and edit the name associated with the menu item you wish to modify (for example, menuItem1).