Creating Toolbars and Menus
Note: This topic describes the recommended method for creating menus and toolbars in VCL applications (Windows platform). For cross-platform development, you need to use the FireMonkey actions, organizing them using FMX action lists and the Action List editor. See Using Actions in a FireMonkey Application and Setting Up Action Lists for details.
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:
- Drop an Action Manager onto a form.
- Add actions to the Action Manager, which organizes them into appropriate action lists.
- Create the action bands (that is, the menu or the toolbar) for the user interface.
- 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
- From the Additional category of the Tool palette, drop an Action Manager component (Vcl.ActnMan.TActionManager) onto the form where you want to create the toolbar or menu.
- If you want images on the menu or toolbar, drop an ImageList component from the Win32 category of the Tool palette onto a form. (You need to add the images you want to use to the ImageList or use the one provided.)
- From the Additional category of the Tool palette, drop one or more of the following action bands onto the form:
- 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.
- 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.
- 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've defined the actions, you can drag and drop them onto menus or toolbars like the standard actions.