How to: Create and Customize an Item and Its Item Links

  • 2 minutes to read

The following example shows how you can create and customize an item and its item links.

In this example, a BarButtonItem item is created. Then, two links to this items are added to a bar and submenu. For the second link, a custom caption is assigned. The first link uses the item's default caption.

//A bar manager providing the XtraBars functionality
BarManager bManager;
//Initialize the bManager object
//...bManager = barManager1;

//Create an item, add it to the bar manager's item collection
BarItem item = new BarButtonItem(bManager, "New");
//Set the bar item's ID to allow the bar's layout to be saved and restored correctly
item.Id = bManager.GetNewItemId();

//A bar to which the item will be added
Bar bar1;
//Initialize the bar1 object
//...bar1 = toolBar1;

//A submenu to which the item will be added
BarSubItem subMenu1;
//Initialize the subMenu1 object
//...subMenu1 = mFile;

//Create a link to the item within the bar
BarItemLink link1 = bar1.AddItem(item);
//Create another link to the item within the submenu
BarItemLink link2 = subMenu1.AddItem(item);
//Change the second link's caption
link2.UserCaption = "Create File...";