Home>>Programming>> » How to Create SubMenus and Add Images to Menu Items

How to Create SubMenus and Add Images to Menu Items

Last Updated on August 3, 2018 By hcyaobin

How to create submenus?

Many application menus contain drop-down lists that appear next to a menu item to provide additional, related commands. Such lists are indicated by an arrow to the right of the menu item. C++Builder supports as many levels of such submenus as you want to build into your menu.

Organizing your menu structure this way can save vertical screen space. However, for optimal design purposes you probably want to use no more than two or three menu levels in your interface design. (For pop-up menus, you might want to use only one submenu, if any.)

To create a submenu,

  1. Select the menu item under which you want to create a submenu.
  2. Press Ctrl to create the first placeholder, or right-click and choose Create Submenu.
  3. Type a name for the submenu item, or drag an existing menu item into this placeholder.
  4. Press Enter, or ? to create the next placeholder.
  5. Repeat steps 3 and 4 for each item you want to create in the submenu.
  6. Press Esc to return to the previous menu level.

How to create submenus by demoting existing menus

You can create a submenu by inserting a menu item from the menu bar (or a menu template) between menu items in a list. When you move a menu into an existing menu structure, all its associated items move with it, creating a fully intact submenu. This pertains to submenus as well. Moving a menu item into an existing submenu just creates one more level of nesting.

How to add images to menu items?

Images can help users navigate in menus by matching glyphs and images to menu item action, similar to toolbar images. You can add single bitmaps to menu items, or you can organize images for your application into an image list and add them to a menu from the image list. If you’re using several bitmaps of the same size in your application, it’s useful to put them into an image list.

To add a single image to a menu or menu item, set its Bitmap property to reference the name of the bitmap to use on the menu or menu item.

To add an image to a menu item using an image list:

  1. Drop a TMainMenu or TPopupMenu object on a form.
  2. Drop a TImageList object on the form.
  3. Open the ImageList editor by double clicking on the TImageList object.
  4. Click Add to select the bitmap or bitmap group you want to use in the menu. Click OK.
  5. Set the TMainMenu or TPopupMenu object’s Images property to the ImageList you just created.
  6. Create your menu items and submenu items as described in this topic group.
  7. Select the menu item you want to have an image in the Object Inspector and set the ImageIndex property to the corresponding number of the image in the ImageList (the default value for ImageIndex is -1, which doesn’t display an image).

Note: Use images that are 16 by 16 pixels for proper display in the menu. Although you can use other sizes for the menu images, alignment and consistency problems may result when using images greater than or smaller than 16 by 16 pixels.

Viewing the menus you created.

You can view your menu in the form at design time without first running your program code. (Pop-up menu components are visible in the form at design time, but the pop-up menus themselves are not. Use the Menu Designer to view a pop-up menu at design time.)
To view the menu,

  1. If the form is visible, click the form, or from the View menu, choose the form whose menu you want to view.
  2. If the form has more than one menu, select the menu you want to view from the form’s Menu property drop-down list.

The menu appears in the form exactly as it will when you run the program.

Add a Comment

Your email address will not be published. Required fields are marked *