Creating a Menu Bar


You can use the Menu Design windowV4GKGG to create a menu bar that displays the names of menus available to use in the active window.  You can also write code to make your menu respond dynamically to user preferences or run-time conditions, such as whether a menu command should be unavailable, or whether menu commands should be added or deleted.

To create a menu bar

   1. Click the form5272EF for which you want to create a menu bar.

   2. From the Window menu, choose Menu Design (Ctrl+M), or use the toolbar shortcut:

   3. In the Caption text box, type the menu item caption as you want it displayed on the menu bar.

         To give the user keyboard access to the menu item, type an ampersand (&) before the letter you want to specify as the access key.  At run time, this letter is underlined, and the user can access the menu or command by pressing Alt plus the access key.

         To create a separator bar1Q9LDO in your menu, type a single hyphen (-) in this box.

   4. In the Name text box, type a control name that you'll use to refer to the menu item in code.  This name can be identical to the caption.

   5. Use the left and right arrows to change the level of a menu item (from a higher level to a lower level or vice versa.)  You can have up to four levels of submenus.

         Use the up and down arrows to change the position of a menu item (up or down in the list box.)

         Choose Next to move to the next line and add another item to the menu.

         Choose Insert to add a line before the currently selected line.

         Choose Delete to delete the currently selected line.

   6. Repeat steps 3-5 to add menu items.

   7. Choose OK to accept all the changes and apply them to the selected form.

     The menu you created is visible at design time, but no events are generated until you write code.


Optional features for custom menus:

         In the Index text box, type a number that determines the control's position within the control array8G7Y0UU.

         To assign a shortcut key1PC5IWB to a menu item, select a key from the Shortcut drop-down list.

         Select the Window List check box if you want the current menu control to include the name of open MDI child forms.

         Enter a unique number in the HelpContextID if you plan to provide a context-sensitive Help topic for the current control.

         Select the Checked box1CX4CX1 if you want a small check mark to appear at the left of a menu item to indicate that the control is turned on or to indicate which of several modes is in effect.

         Select the Enabled box8PMG97 if you want the menu item to initially respond to events1L2S0SZ.  Clear the box if you want the menu item to be unavailable and appear dimmed on the menu.  An initially unavailable item can later be enabled in code.

         Select the Visible box4QUHQV if you want the menu item to appear on the menu.


Note   For details on the properties3MRB2KQ, events1L2S0SZ, and methods1XB6QBF that apply to menus, see the MenuBKDT1F topic.


See Also


Attaching an Event Procedure to a Form or Control2LBGK4C

Creating a Menu Control Array131TFDP

Specifying Access KeysIFK11S


Learning Visual Basic:

Adding Menus


Programmer's Guide:

Chapter 4, "Menus and Dialogs"