Skip to main content
A newer version of this page is available. .
Bar

BarManager.ShowToolbarsContextMenu Event

Allows you to modify the customization menu before it is displayed onscreen.

Namespace: DevExpress.XtraBars

Assembly: DevExpress.XtraBars.v18.2.dll

Declaration

[DXCategory("Events")]
public event ShowToolbarsContextMenuEventHandler ShowToolbarsContextMenu

Event Data

The ShowToolbarsContextMenu event's data class is ShowToolbarsContextMenuEventArgs. The following properties provide information specific to this event:

Property Description
ItemLinks Provides access to the links that are going to be displayed within the customization menu.

Remarks

The customization menu allows the end-user to specify the visibility state of toolbars. It displays the bars for which the BarOptions.Hidden property is set to false.

By default, the customization menu is displayed when the end-user right-clicks on a toolbar. You can disable the default behavior by setting the BarManager.AllowShowToolbarsPopup property to false. The customization menu can also be invoked manually by calling BarManager.ShowToolBarsPopup.

Use the ShowToolbarsContextMenu event to customize the menu before it is displayed onscreen. For instance, you can add specific links to the menu or remove existing ones as required. The links to display within the menu are passed as the ShowToolbarsContextMenuEventArgs.ItemLinks parameter.

Example

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 “www.devexpress.com” 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:

BarManager_ShowToolbarsContextMenu

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
    barManager1.RepositoryItems.Add(ri);
    //Assign the repository item to the bar item
    item.Edit = ri;
    //Provide the initial value for the editor
    item.EditValue = "www.devexpress.com";
    //Name the bar item
    item.Name = "MyHyperlinkItem";
    //Add the bar item to the bar manager
    barManager1.Items.Add(item);
}

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;
}
See Also