This document is archived and information here might be outdated.  Recommended version.


ICommandBar Interface (ArcObjects .NET 10.5 SDK)
ArcObjects Library Reference (Framework)  

ICommandBar Interface

Provides access to members that modify a commandbar.

Product Availability

Available with ArcGIS Desktop.

When To Use

A CommandBar is a toolbar, menubar, menu, or context menu in the application. Use the ICommandBar interface to add commands, menus, or macro items to an existing command bar. Also use this interface to postion the command bar in the application.

Members

Description
Method Add Adds a new command to this commandbar.
Read-only property Count The number of items contained within this commandbar.
Method CreateMacroItem Creates a new macro item on this commandbar at the specified position.
Method CreateMenu Creates a new blank menu on this commandbar at the specified position.
Method Dock Docks or undocks this commandbar.
Method Find Finds a command on this commandbar.
Method IsVisible Indicates if this commandbar is visible.
Read-only property Item The command item on this commandbar at the specified index.
Method Popup Displays this commandbar as a popup menu at the specified location.

CoClasses that implement ICommandBar

CoClasses and Classes Description
CommandBar CommandBar object.

Remarks

Use the CommandBars collection on a Document object to get a reference to a command bar object.

Note, all programmatic customizations are temporary. If you execute VBA code to modify a commandbar or create a new menu, these changes are temporary. If you programmatically customize ArcMap, these changes will only appear while the current document is open in the current ArcMap session. Programmatic changes are never saved in the document or templates. Once you close that document or shutdown ArcMap, the changes are removed. If you are customizing ArcCatalog, these changes will only appear during the current ArcCatalog session.

The following example shows how to use the ICommandBars::Create method to create a new toolbar in Arcmap and add some items to it using the CommandBar::Add method. You would get m_app from the hook in ICommand::OnCreate().

[C#]
ICommandBars commandBars=m_app.Document.CommandBars;
ICommandBar newBar=commandBars.Create("MyBar", esriCmdBarType.esriCmdBarTypeToolbar);
UID uid=new UIDClass();
uid.Value="{E1F29C6B-4E6B-11D2-AE2C-080009EC732A}";
object index=0;
newBar.Add(uid, ref index);
UID uid2=new UIDClass();
uid2.Value="{0830FB35-7EE6-11D0-87EC-080009EC732A}";
object index2=1;
newBar.Add(uid2, ref index2);
[Visual Basic .NET]
Dim commandBars As ICommandBars=m_app.Document.CommandBars
Dim newBar As ICommandBar=commandBars.Create("MyBar", esriCmdBarType.esriCmdBarTypeToolbar)
Dim uid As UID=New UIDClass()
uid.Value="{E1F29C6B-4E6B-11D2-AE2C-080009EC732A}"
Dim index As Object=0
newBar.Add(uid, index)
Dim uid2 As UID=New UIDClass()
uid2.Value="{0830FB35-7EE6-11D0-87EC-080009EC732A}"
Dim index2 As Object=1
newBar.Add(uid2, index2)

See Also

ICommandBars.Find Method

.NET Snippets

Create Context Menu | Get Command on Toolbar by Names | Get Toolbar by Name

.NET Samples

Layer filtering TOC view (Code Files: TOCLayerFilter) | Applying user interface customizations at startup (Code Files: AcmeExt) | Simple logging dockable window with a custom context menu (Code Files: LoggingDockableWindow)

.NET Related Topics

How to show a context menu in ArcGIS for Desktop applications