windowsforms-116781-controls-and-libraries-ribbon-bars-and-menu-bars-tutorials-add-and-remove-toolbars.md
This document describes existing toolbar types and how to add them.
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.
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();
}
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.
var bar = barManager1.Bars["Image Toolbar"];
Dim bar = barManager1.Bars("Image Toolbar")
See Also