ArcObjects Library Reference (Framework)  

ICommandBars.Create Method

Creates a new blank toolbar or shortcut menu.

[Visual Basic .NET]
Public Function Create ( _
    ByVal Name As String, _
    ByVal barType As esriCmdBarType _
) As ICommandBar
[C#]
public ICommandBar Create (
    string Name,
    esriCmdBarType barType
);

Product Availability

Available with ArcGIS Desktop.

Description

 

Name is a string representing the name of the new toolbar or shortcut menu.

barType specifies which type of commandbar to create. Use one of the esriCmdBarType constants.

Remarks

The Create method creates a new VBA command bar in a visible, floating state.

To create new menu in VBA, use the ICommandBar CreateMenu method instead of the ICommandBars Create method.

If you want to create a new command bar in a development environment other than VBA, you should implement either IToolBarDef or IMenuDef instead of using the ICommandBars Create method.

Note, all programmatic customizations are temporary. If you execute VBA code to create a new commandbar, 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 Interface | esriCmdBarType Constants | ICommandBar Interface

.NET Snippets

Create Context Menu |