Back to Devexpress

Add and Remove Toolbars

windowsforms-116781-controls-and-libraries-ribbon-bars-and-menu-bars-tutorials-add-and-remove-toolbars.md

latest3.7 KB
Original Source

Add and Remove Toolbars

  • Oct 29, 2020
  • 4 minutes to read

This document describes existing toolbar types and how to add them.

Initial Setup

  • Locate the BarManager component in the VS Toolbox and drop it onto the form. The Bar Manager is the core component of the DevExpress Bars library and provides centralized access to all toolbars, menus and items.
  • The BarManager automatically creates three toolbars - main menu , regular toolbar and status bar.

Add and Remove Toolbars

To remove a bar, first click it at design-time. The selected bar will become highlighted.

Press the “DELETE” key to remove the selected bar.

To add a bar, invoke the BarManager’s smart tag and click “Create Toolbar”.

Another way to add a toolbar is to invoke the BarManager component’s smart tag and click “Customize”. This will invoke the Customization Window dialog where you can add and remove toolbars, as well as reset their settings to default values.

The added Bar will be a regular toolbar, docked below other toolbars of this type. You can instantly re-arrange bars by dragging them at design time.

Code Sample

csharp
public void InitializeBars() {
    BarManager bManager = new BarManager();
    bm = bManager;
    bManager.Form = this;
    //All bar modifications should be performed between the BeginUpdate and EndUpdate method calls
    bManager.BeginUpdate();
    //Create three toolbars
    Bar mainBar = new Bar(bm, "Main Menu") { DockStyle = BarDockStyle.Top, DockRow = 0 };
    Bar statusBar = new Bar(bm, "Status Bar") { DockStyle = BarDockStyle.Bottom };
    Bar toolbar1 = new Bar(bm, "File Toolbar") { DockStyle = BarDockStyle.Top };
    //Set the existing Bar Manager as your bars' parent
    bManager.Bars.AddRange(new Bar[] { mainBar, statusBar, toolbar1 });
    //Choose main menu and status bars
    bManager.MainMenu = mainBar;
    bManager.StatusBar = statusBar;
    bManager.EndUpdate();
}
vb
Public Sub InitializeBars()
    Dim bManager As New BarManager()
    bm = bManager
    bManager.Form = Me
    'All bar modifications should be performed between the BeginUpdate and EndUpdate method calls
    bManager.BeginUpdate()
    'Create three toolbars
    Dim mainBar As New Bar(bm, "Main Menu") With {.DockStyle = BarDockStyle.Top, .DockRow = 0}
    Dim statusBar As New Bar(bm, "Status Bar") With {.DockStyle = BarDockStyle.Bottom}
    Dim toolbar1 As New Bar(bm, "File Toolbar") With {.DockStyle = BarDockStyle.Top}
    'Set the existing Bar Manager as your bars' parent
    bManager.Bars.AddRange(New Bar() { mainBar, statusBar, toolbar1 })
    'Choose main menu and status bars
    bManager.MainMenu = mainBar
    bManager.StatusBar = statusBar
    bManager.EndUpdate()
End Sub

You can access created toolbars by their Bar.BarName property values.

csharp
var bar = barManager1.Bars["Image Toolbar"];
vb
Dim bar = barManager1.Bars("Image Toolbar")

See Also

Add Bar Items To Toolbars