Skip to main content

How to: Add Items to Bars' Customization Menu

  • 3 minutes to read

The following example shows how you can handle the BarManager.ShowToolbarsContextMenu event to manipulate the customization menu. In this example, a new bar item link representing the hyperlink editor is added to the menu. This editor displays “” as text, clicking on this opens a browser window at the specified address.

The bar item providing the editing facilities is a BarEditItem. To associate a specific editor with the bar item, we create a corresponding repository item object which contains edit type information and edit settings and add it to the BarManager’s ComponentEditorContainer.RepositoryItems collection, then assign it to the BarEditItem.Edit property. The bar item is created and customized in the form’s Load event handler.

The image below shows the customization menu with the new item:


using XtraEditors.Repository;
private void frmMain_Load(object sender, System.EventArgs e) {
    //Create a new bar item representing a hyperlink editor
    BarEditItem item = new BarEditItem();
    //Create and customize a repository item representing a hyperlink editor
    RepositoryItemHyperLinkEdit ri = new RepositoryItemHyperLinkEdit();
    ri.SingleClick = true;
    //Add the repository item to the internal repository
    //Assign the repository item to the bar item
    item.Edit = ri;
    //Provide the initial value for the editor
    item.EditValue = "";
    //Name the bar item
    item.Name = "MyHyperlinkItem";
    //Add the bar item to the bar manager

private void barManager1_ShowToolbarsContextMenu(object sender, 
  ShowToolbarsContextMenuEventArgs e) {
    BarManager barManager = sender as BarManager;
    //Get the bar item by its name and create a link to it in the customization menu
    BarItemLink link = e.ItemLinks.Add(barManager.Items["MyHyperlinkItem"]);
    //Customize the link
    link.Width = 120;
    link.BeginGroup = true;