下面的示例展示了如何创建和定制一个 item 及其 links。

在本例中,创建了一个 BarButtonItem 项。 然后,此 item 的两个 links 被分别添加到 bar 和子菜单中。 为第二个 link 指定了自定义标题。 第一个 link 则使用 item 的默认标题。

C#CopyCode image复制代码
//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...";
Visual BasicCopyCode image复制代码
'A bar manager providing the XtraBars functionality
Dim bManager As BarManager
'Initialize the bManager object
'...bManager = barManager1
     
'Create an item, add it to the bar manager's item collection
Dim item As BarItem = 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
Dim bar1 As Bar
'Initialize the bar1 object
'...bar1 = toolBar1

'A submenu to which the item will be added
Dim subMenu1 As BarSubItem
'Initialize the subMenu1 object
'...subMenu1 = mFile

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