RAD Studio
ContentsIndex
PreviousUpNext
Building Application Menus

Menus provide an easy way for your users to execute logically grouped commands. You can add or delete menu items, or drag them to rearrange them during designtime. In addition to TMainMenu and TPopupMenu components, the Tool Palette also contains TActionMainMenuBar, TActionManager, and TActionToolBar.

To create application menus

  1. Choose FileNewOther. The New Items dialog appears.
  2. In the New Items dialog, select VCL Forms Application. The Windows Designer displays.
  3. Build application menus.
  4. Use the Menu Designer.
  5. Create an event handler for each menu item.
  6. Move menu items.
  7. Add images to menu items.

To build application menus

  1. From the Standard category of the Tool Palette, add TMainMenu or TPopupMenu component to your form. A visual representation of the menu appears on the designer.
    Note: A TMainMenu
    component creates a menu that is attached to the title bar of the form. A TPopupMenu component creates a menu that appears when the user right-clicks in the form.
  2. To view the menu, if the form is visible, click the form. The menu appears in the form exactly as it will when you run the program.
  3. To delete a menu item, select the menu item you want to delete. Press Delete.
  4. To edit menu items, select the VCL form, select the menu item you want to edit, and edit its properties.
  5. To make the menu item a separator bar, place the cursor on the menu where you want a separator to appear and enter a hyphen (-) for the caption or press the hyphen (-) key.
  6. To specify a keyboard shortcut for a menu item, in the Object Inspector, set the ShortCut property.

To use the Menu Designer

  1. Select a menu component on the form.
  2. Double-click the menu component. The Menu Designer window opens.
    Note: You can also open the Menu Designer
    by clicking the ellipsis(...) button next to the Items property in the Object Inspector.
  3. To name a menu component, in the Object Inspector, set the Caption property.
    Tip: Delphi derives the Name property from the caption, for e.g. if you give a menu item a Caption property value of File, Delphi assigns the menu item a Name property of File1. However, if you fill in the Name property before filling in the Caption property, Delphi leaves the Caption property blank until you type a value.
  4. Right-click anywhere on the Menu Designer to use the Menu Designer context menu. A drop-down list opens. This is the Menu Designer context menu.
  5. To insert a placeholder below or to the right of the cursor, choose Insert from the context menu.
  6. To delete the selected menu item (and all its subitems, if any), click Delete from the context menu.
  7. To switch among menus in a form, choose Select Menu from the context menu. The Select Menu dialog box appears. It lists all the menus associated with the form whose menu is currently open in the Menu designer.
  8. From the list in the Select Menu dialog box, choose the menu you want to view or edit.

To create an event handler for a menu item

  1. In the designer, double-click the menu item to which you wish to add an event handler. The Code Designer appears, cursor in place between event handler brackets.
  2. Code your menu item logic.
  3. Save and compile the application.

To move menu items

  1. To move a menu item along the desired menu bar, drag the item until the arrow tip of the cursor points to the new location.
  2. Release the mouse button.
  3. To move a menu item into a menu list, drag the item until the arrow tip of the cursor points to the new menu.
  4. Release the mouse button.

To add images to menu items

  1. From the Tool Palette, drag a TMainMenu or TPopupMenu component to a form.
  2. From the Tool Palette, drop a TImageList component to the form.
  3. Double-click on the TImageList component. The ImageList editor opens.
  4. Click Add to select the bitmap or bitmap group you want to use in the menu.
  5. Select the bitmap that you want and click OK.
  6. In the Object Inspector, set the Images property of the TMainMenu or TPopupMenu component to the image you selected in the ImageList editor.

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!