Home>>Programming>>C++Builder>> » How to Create Toolbars and Menus and Add Color, Patterns, or Pictures to the Menus, Buttons, and Toolbars

How to Create Toolbars and Menus and Add Color, Patterns, or Pictures to the Menus, Buttons, and Toolbars

Last Updated on August 7, 2018 By hcyaobin

How to creating toolbars and menus in C Builder?

You use the Action Manager to automatically generate toolbars and main menus based on the actions contained in your application. The Action Manager manages standard actions and any custom actions that you have written. You then create UI elements based on these actions and use action bands to render the actions items as either menu items or as buttons on a toolbar.

The general procedure for creating menus, toolbars, and other action bands involves these steps:

  1. Drop an Action Manager onto a form.
  2. Add actions to the Action Manager, which organizes them into appropriate action lists.
  3. Create the action bands (that is, the menu or the toolbar) for the user interface.
  4. Drag and drop the actions into the application interface.

The following procedure explains these steps in more detail.
To create menus and toolbars using action bands:

  1. From the Additional page of the Component palette, drop an Action Manager component (TActionManager) onto the form where you want to create the toolbar or menu.
  2. If you want images on the menu or toolbar, drop an ImageList component from the Win32 page of the Component palette onto a form. (You need to add the images you want to use to the ImageList or use the one provided.)
  3. From the Additional page of the Component palette, drop one or more of the following action bands onto the form:
    TActionMainMenuBar (for designing main menus)
    TActionToolBar (for designing toolbars)
  4. Connect the ImageList to the Action Manager: with focus on the Action Manager and in the Object Inspector, select the name of the ImageList from the Images property.
  5. Add actions to the Action Manager editor’s action pane:
    Double-click the Action Manager to display the Action Manager editor.
    Click the drop-down arrow next to the New Action button (the leftmost button at the top right corner of the Actions tab) and select New Action or New Standard Action. A tree view is displayed. Add one or more actions or categories of actions to the Action Manager’s actions pane. The Action Manager adds the actions to its action lists.
  6. Drag and drop single actions or categories of actions from the Action Manager editor onto the menu or toolbar you are designing.

To add user-defined actions, create a new TAction by pressing the New Action button and writing an event handler that defines how it will respond when fired. See What happens when an action fires for details. Once you’re defined the actions, you can drag and drop them onto menus or toolbars like the standard actions.

Note: This section describes the recommended method for creating menus and toolbars in Windows applications. For cross-platform development, you need to use TToolBar and the menu components, such as TMainMenu, organizing them using action lists (TActionList). See Setting up action lists for details.

How to add color, patterns, or pictures to menus, buttons, and toolbars in C Builder?

You can use the Background and BackgroundLayout properties to specify a color, pattern, or bitmap to use on a menu item or button. These properties also let you set up a banner the runs up the left or right side of a menu.

You assign backgrounds and layouts to subitems from their action client objects. If you want to set the background of the items in a menu, in the form designer click on the menu item that contains the items. For example, selecting File lets you change the background of items appearing on the File menu. You can assign a color, pattern, or bitmap in the Background property in the Object Inspector.

Use the BackgroundLayout property to describe how to place the background on the element. Colors or images can be placed behind the caption normally, stretched to fit the item area, or tiled in small squares to cover the area.

Items with normal (blNormal), stretched (blStretch), or tiled (blTile) backgrounds are rendered with a transparent background. If you create a banner, the full image is placed on the left (blLeftBanner) or the right (blRightBanner) of the item. You need to make sure it is the correct size because it is not stretched or shrunk to fit.

To change the background of an action band (that is, on a main menu or toolbar), select the action band and choose the TActionClientBar through the action band collection editor. You can set Background and BackgroundLayout properties to specify a color, pattern, or bitmap to use on the entire toolbar or menu.

Add a Comment

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