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


Get Toolbar by Name Snippet (ArcObjects .NET 10.5 SDK)
ArcObjects Library Reference

Get Toolbar by Name Snippet

Obtain a toolbar by specifying it's name.

[C#]
///<summary>Obtain a toolbar by specifying it's name.</summary>
///  
///<param name="application">An IApplication interface.</param>
///<param name="toolbarName">A System.String that is the name of the toolbar to return. Example: "esriArcMapUI.StandardToolBar"</param>
///   
///<returns>An ICommandBar interface.</returns>
///  
///<remarks>Refer to the EDN document http://edndoc.esri.com/arcobjects/9.1/default.asp?URL=/arcobjects/9.1/ArcGISDevHelp/TechnicalDocuments/Guids/ArcMapIds.htm for a listing of available CLSID's and ProgID's that can be used as the toolbarName parameter.</remarks>
public ESRI.ArcGIS.Framework.ICommandBar GetToolbarByName(ESRI.ArcGIS.Framework.IApplication application, System.String toolbarName)
{
  ESRI.ArcGIS.Framework.ICommandBars commandBars=application.Document.CommandBars;
  ESRI.ArcGIS.esriSystem.UID barID=new ESRI.ArcGIS.esriSystem.UIDClass();
  barID.Value=toolbarName; // Example: "esriArcMapUI.StandardToolBar"
  ESRI.ArcGIS.Framework.ICommandItem commandItem=commandBars.Find(barID, false, false);
  if (commandItem != null && commandItem.Type == ESRI.ArcGIS.Framework.esriCommandTypes.esriCmdTypeToolbar)
  {
    return (ESRI.ArcGIS.Framework.ICommandBar)commandItem;
  }
  else
    return null;
}
[Visual Basic .NET]
'''<summary>Obtain a toolbar by specifying it's name.</summary>
'''  
'''<param name="application">An IApplication interface.</param>
'''<param name="toolbarName">A System.String that is the name of the toolbar to return. Example: "esriArcMapUI.StandardToolBar"</param>
'''   
'''<returns>An ICommandBar interface.</returns>
'''  
'''<remarks>Refer to the EDN document http://edndoc.esri.com/arcobjects/9.1/default.asp?URL=/arcobjects/9.1/ArcGISDevHelp/TechnicalDocuments/Guids/ArcMapIds.htm for a listing of available CLSID's and ProgID's that can be used as the toolbarName parameter.</remarks>
Public Function GetToolbarByName(ByVal application As ESRI.ArcGIS.Framework.IApplication, ByVal toolbarName As System.String) As ESRI.ArcGIS.Framework.ICommandBar

  Dim commandBars As ESRI.ArcGIS.Framework.ICommandBars=application.Document.CommandBars
  Dim barID As ESRI.ArcGIS.esriSystem.UID=New ESRI.ArcGIS.esriSystem.UIDClass
  barID.Value=toolbarName ' Example: "esriArcMapUI.StandardToolBar"
  Dim commandItem As ESRI.ArcGIS.Framework.ICommandItem=commandBars.Find(barID, False, False)

  If Not (commandItem Is Nothing) AndAlso commandItem.Type=ESRI.ArcGIS.Framework.esriCommandTypes.esriCmdTypeToolbar Then

    Return CType(commandItem, ESRI.ArcGIS.Framework.ICommandBar)

  Else

    Return Nothing

  End If

End Function

Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.Framework
  • ESRI.ArcGIS.System