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


IToolbarControl2.AddToolbarDef Method (ArcObjects .NET 10.5 SDK)
ArcObjects Library Reference (Controls)  

IToolbarControl2.AddToolbarDef Method

Appends the contents of the toolbar definition, specified by Guid or ToolbarDef, to the toolbar control.

[Visual Basic .NET]
Public Function AddToolbarDef ( _
    ByVal ToolbarDef As Object, _
    [ByVal startIndex As Integer], _
    [ByVal Group As Boolean], _
    [ByVal GroupSpacing As Integer], _
    [ByVal Style As esriCommandStyles] _
) As Integer
[C#]
public int AddToolbarDef (
    object ToolbarDef,
    int startIndex,
    bool Group,
    int GroupSpacing,
    esriCommandStyles Style
);
[C#]

Optional Values

startIndex   Supply -1 as a default value.
Group   Supply false as a default value.
GroupSpacing   Supply 4 as a default value.
Style   Supply esriCommandStyleIconOnly as a default value.
[C++]
HRESULT AddToolbarDef(
  VARIANT ToolbarDef,
  long startIndex,
  VARIANT_BOOL Group,
  long GroupSpacing,
  esriCommandStyles Style,
  long* Count
);
[C++]

Parameters ToolbarDef [in] ToolbarDef is a parameter of type VARIANT startIndex [in, optional, defaultvalue(-1)] startIndex is a parameter of type long Group [in, optional, defaultvalue(VARIANT_FALSE)] Group is a parameter of type VARIANT_BOOL GroupSpacing [in, optional, defaultvalue(4)] GroupSpacing is a parameter of type long Style [in, optional, defaultvalue(1)]
Style is a parameter of type esriCommandStyles Count [out, retval] Count is a parameter of type long

Product Availability

Available with ArcGIS Engine.

Description

Takes the specified toolbar definition and for each command specified an item is created and added to the ToolbarControl with an associated IToolbarItem::Command set. Specifiy the toolbar definition as either a IUid, ProgID, or IToolBarDef .

startIndex determines the position on the ToolbarControl each item will be added to. By default this is -1 and represents the end of the ToolbarControl.

Group determines whether separators will appear before the first and after the last item defined by the IToolBarDef . By default Group is False. Note this will override any IItemDef::Group property set in the IToolBarDef.

GroupSpacing determines the width of any separators, and applies to all item's defined by the IToolBarDef .

Style applies to all item's defined by the IToolBarDef. By default Style is set to esriCommandStyleIconOnly.

Where possible always supply toolbars as either Uid objects or ProgID's. Only supply toolbars as IToolBarDef objects when a IUid or ProgID does not exist, and the class is compiled as part of the same project using the ToolbarControl.

Errors Returned

1005: The value of a parameter which is an enumerated constant is out of the range of required values

1023: The specified index is out of range

1042: The supplied toolbar def object is invalid or contains zero commands

Remarks

For each command specified by the IToolBarDef, AddToolbarDef calls the AddItem method which checks to see if the supplied command already exists in the CommandPool. If the command does not already exist, it is added to the CommandPool with a ICommandPool::UsageCount of 1, and is set as the IToolbarItem::Command. If the command does already exist in the CommandPool its ICommandPool::UsageCount increments by 1 and the command is set as the IToolbarItem::Command. The ICommand::OnCreate method will only be called the first time a command is added to the CommandPool.

[C#]
//Add a toolbardef by passing a UID
UID uID=new UIDClass();
uID.Value="esriControls.ControlsMapNavigationToolbar";
axToolbarControl1.AddToolbarDef(uID,-1,false,0,esriCommandStyles.esriCommandStyleIconOnly);

//Add a toolbardef by passing a ProgID
string progID="esriControls.ControlsMapNavigationToolbar";
axToolbarControl1.AddToolbarDef(progID,-1,false,0,esriCommandStyles.esriCommandStyleIconOnly);

//Add a toolbardef by passing an IToolbarDef 
IToolBarDef toolBarDef=new ControlsMapNavigationToolbarClass();
axToolbarControl1.AddToolbarDef(toolBarDef,-1,false,0,esriCommandStyles.esriCommandStyleIconOnly);
[Visual Basic .NET]
'Add a toolbardef by passing a UID
Dim pUid As New UIDClass
pUid.Value="esriControls.ControlsMapNavigationToolbar"
AxToolbarControl1.AddToolbarDef(pUid)

'Add a toolbardef by passing a ProgID
Dim sProgID As String
sProgID="esriControls.ControlsMapNavigationToolbar"
AxToolbarControl1.AddToolbarDef(sProgID)

'Add a toolbardef by passing an IToolbarDef
Dim pToolBarDef As IToolBarDef
pToolBarDef=New ControlsMapNavigationToolbarClass
AxToolbarControl1.AddToolbarDef(pToolBarDef)

See Also

IToolbarControl2 Interface