Skip to main content

Creating Toolbar Items and Item Controls

  • 3 minutes to read

This topic describes how you can create bar items and their item controls at design time, runtime and in code. Select one of the following links to jump to the desired section of this topic.

At Design Time

At Runtime

In Code

At Design Time

To create an item, item link, and item control and add the latter to the selected toolbar, click Add Item… (or Add cxEditItem if you have the ExpressEditors Library installed) in the Toolbars Popup Menu or Customizing Popup Menu.

In addition, you can use the Commands page of the Customization Form to create a bar item. To do this:

  • click the modify… button on the Commands panel to display a dropdown menu;

  • click Add… in this dropdown menu.

This displays the Add New ExpressBars Item dialog box, which allows you to specify the type, category, name and caption of a new item.

At Runtime

End-users can create an item control for an existing bar item by dragging the item from the Commands page in the Customization Form to the desired toolbar. For more information on how this can be accomplished, refer to the Using Drag and Drop help topic.

In Code

To programmatically create a bar item, call a bar manager’s AddItem method and pass the item type as the AClass parameter. To create a button or subitem, you can call the AddButton or AddSubItem functions respectively.

The following code snippet demonstrates how to create a TdxBarLargeButton and specify its caption and image.

var ALargeButton: TdxBarItem;
// ...
// creating a large button
ALargeButton := dxBarManager1.AddItem(TdxBarLargeButton);
// setting the caption and image
ALargeButton.Caption := '&New';
TdxBarLargeButton(ALargeButton).LargeImageIndex := 0;
// ...

To add an existing item to a toolbar or submenu, an item link must be created. Call the Add method of the desired toolbar or submenu’s ItemLinks collection. This is demonstrated in the following example.

var ALargeButton: TdxBarItemLink;
// ...
// creating an item link for an existing item
ALargeButton := dxBarManager1Bar1.ItemLinks.Add(dxBarLargeButton1);
// setting the caption for the item link
ALargeButton.UserCaption := 'NewFile';
// ...

To create an item and add its item control to a toolbar or submenu, call the AddItem function of the desired toolbar or submenu’s ItemLinks collection, and pass the item type as the AItemClass parameter. Use the AddButton and AddSubItem functions to create a button and subitem respectively.

The following code sample demonstrates how to create a TdxBarLargeButton and its item link on a toolbar.

var ALargeButton: TdxBarItemLink;
// ...
// creating a large button and displaying it on the first toolbar
ALargeButton := dxBarManager1Bar1.ItemLinks.AddItem(TdxBarLargeButton);
// setting the caption and image
ALargeButton.Item.Caption := '&New';
TdxBarLargeButton(ALargeButton.Item).LargeImageIndex := 0;
// ...

Refer to the How to Create Items at Runtime and Place them on a Toolbar or a Submenu and How to Create Several Item Controls for the Same Underlying Item help topics for additional code samples related to bar items and item links.

See Also