ArcObjects Library Reference (Controls)  

IToolbarControlDefault.AddMenuItem Method

Adds a menu item to the ToolbarControl.

[Visual Basic .NET]
Public Function AddMenuItem ( _
    ByVal Menu As Object, _
    [ByVal index As Integer], _
    [ByVal beginGroup As Boolean], _
    [ByVal GroupSpacing As Integer] _
) As Integer
[C#]
public int AddMenuItem (
    object Menu,
    int index,
    bool beginGroup,
    int GroupSpacing
);
[C#]

Optional Values

index   Supply -1 as a default value.
beginGroup   Supply false as a default value.
GroupSpacing   Supply 4 as a default value.
[C++]
HRESULT AddMenuItem(
  VARIANT Menu,
  long index,
  VARIANT_BOOL beginGroup,
  long GroupSpacing,
  long* itemIndex
);
[C++]

Parameters

Menu [in]   Menu is a parameter of type VARIANT index [in, optional, defaultvalue(-1)]   index is a parameter of type long beginGroup [in, optional, defaultvalue(VARIANT_FALSE)]   beginGroup is a parameter of type VARIANT_BOOL GroupSpacing [in, optional, defaultvalue(4)]   GroupSpacing is a parameter of type long itemIndex [out, retval]   itemIndex is a parameter of type long

Product Availability

Available with ArcGIS Engine.

Description

Takes the specified menu and creates a new item that is added to the ToolbarControl and returns the index of the menu item added. This is really a shortcut to AddItem.

Specifiy the menu as either a IUID , ProgID, IMenuDef or IToolbarMenu.

If AddIMenuItem is passed an IMenuDef, the menu definition is is used to build a new ToolbarMenu, and the IToolbarMenu::CommandPool is set to the IToolbarControlDefault::CommandPool. If AddMenuItem is passed an IToolbarMenu a new ToolbarItem is created and the IToolbarItem::Menu is set to the IToolbarMenu.

index determines the position on the ToolbarControl that the Item will be added to. By default this is -1 and represents the end of the ToolbarControl.

beginGroup determines whether a separator will appear before the Item. By default beginGroup is False.

GroupSpacing determines the width in pixels of the separator.

Errors Returned

1023 800a03ff: The specified index is out of range
1047 800a0417: Errors occurred adding the specified menu to the toolbar
1064 800a0428: A command or a toolbar cannot be added as a menu item.

Remarks

AddItem checks to see if each command in the menu already exists in the CommandPool used by the ToolbarControl. If the command does not already exist, it is created and added to the CommandPool with a ICommandPool::UsageCount of 1. If the command already exists in the CommandPool its ICommandPool::UsageCount is incremented by 1. The ICommand::OnCreate method will be called the first time a command is added to the CommandPool.

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

[C#]
//Add menu by passing a UID
UID uID = new UIDClass();
uID.Value = "esriControls.ControlsMapViewMenu";
axToolbarControl1.AddMenuItem(uID,-1,false,0);

//Add menu by passing a ProgID
string progID  = "esriControls.ControlsMapViewMenu";
axToolbarControl1.AddMenuItem(progID,-1,false,0);
[Visual Basic .NET]
'Add menu by passing a UID
Dim pUid As New UIDClass
pUid.Value = "esriControls.ControlsMapViewMenu"
AxToolbarControl1.AddMenuItem(pUid)

'Add menu by passing a ProgID
Dim sProgID As String
sProgID = "esriControls.ControlsMapViewMenu"
AxToolbarControl1.AddMenuItem(sProgID)

See Also

IToolbarControlDefault Interface