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


Create PopUp ToolbarMenu Snippet (ArcObjects .NET 10.6 SDK)
ArcObjects Library Reference

Create PopUp ToolbarMenu Snippet

Stub code for creating a popup or context menu.

[C#]
/// <summary>
/// Member variable for the ToolbarMenu.
/// </summary>
/// <remarks>This snippet assumes a ToolbarControl has a MapControl, PageLayoutControl GlobeControl 
/// or SceneControl buddy set.</remarks>
public ESRI.ArcGIS.Controls.IToolbarMenu m_ToolbarMenu;

/// <summary>
/// Create the ToolbarMenu. 
/// </summary>
/// <param name="toolbarControl"></param>
/// <remarks>
/// Call to create a ToolbarMenu. For example, if a ToolbarControl
/// named AxToolbarControl1 exists use the following code:
/// CreateToolbarMenu(AxToolbarControl1.Object)
/// </remarks>
public void CreateToolbarMenu(ESRI.ArcGIS.Controls.IToolbarControl toolbarControl)
{
  // Create a new ToolbarMenu
  m_ToolbarMenu=new ESRI.ArcGIS.Controls.ToolbarMenuClass();

  // Share the ToolbarControl's command pool
  m_ToolbarMenu.CommandPool=toolbarControl.CommandPool;

  // Set the hook
  m_ToolbarMenu.SetHook(toolbarControl.Buddy);

  // Add commands items to the ToolbarMenu. 
  // Add additional commands based on the mapping control being used
  // For a listing of the ArcGIS Engine Controls CLSID or ProgID see: MS.VSCC.v80/MS.VSIPCC.v80/ESRI.EDNv9.2/NET_Engine/shared/reference/guids_ctrls_cmds.htm
  m_ToolbarMenu.AddItem("esriControls.ControlsAddDataCommand", -1, -1, false, ESRI.ArcGIS.SystemUI.esriCommandStyles.esriCommandStyleIconOnly);
}

/// <summary>
/// Open the Context Menu popup for the ToolbarMenu.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="hWnd"></param>
/// <remarks>
/// Call to popup the ToolbarMenu on the display of the ToolbarControl's buddy. 
/// For example, if AxToolbarControl1 is buddied to AxMapControl1 use the following 
/// code from one of the MapControl's mouse events:
/// PopupToolbarMenu(e.x, e.y, AxMapControl1.hWnd)
/// </remarks>
public void PopupToolbarMenu(System.Int32 x, System.Int32 y, System.Int32 hWnd)
{
  m_ToolbarMenu.PopupMenu(x, y, hWnd);
}
[Visual Basic .NET]
''' <summary>
''' Member variable for the ToolbarMenu.
''' </summary>
''' <remarks>This snippet assumes a ToolbarControl has a MapControl, PageLayoutControl GlobeControl 
''' or SceneControl buddy set.</remarks>
Private m_ToolbarMenu As ESRI.ArcGIS.Controls.IToolbarMenu

''' <summary>
''' Create the ToolbarMenu. 
''' </summary>
''' <param name="toolbarControl"></param>
''' <remarks>
''' Call to create a ToolbarMenu. For example, if a ToolbarControl
''' named AxToolbarControl1 exists use the following code:
''' CreateToolbarMenu(AxToolbarControl1.Object)
''' </remarks>
Private Sub CreateToolbarMenu(ByVal toolbarControl As ESRI.ArcGIS.Controls.IToolbarControl)

  ' Create a new ToolbarMenu
  m_ToolbarMenu=New ESRI.ArcGIS.Controls.ToolbarMenuClass()

  ' Share the ToolbarControl's command pool
  m_ToolbarMenu.CommandPool=toolbarControl.CommandPool

  ' Set the hook
  m_ToolbarMenu.SetHook(toolbarControl.Buddy)

  ' Add commands items to the ToolbarMenu. 
  ' Add additional commands based on the mapping control being used
  ' For a listing of the ArcGIS Engine Controls CLSID or ProgID see: MS.VSCC.v80/MS.VSIPCC.v80/ESRI.EDNv9.2/NET_Engine/shared/reference/guids_ctrls_cmds.htm
  m_ToolbarMenu.AddItem("esriControls.ControlsAddDataCommand", -1, -1, False, ESRI.ArcGIS.SystemUI.esriCommandStyles.esriCommandStyleIconOnly)

End Sub

''' <summary>
''' Open the Context Menu popup for the ToolbarMenu.
''' </summary>
''' <param name="x"></param>
''' <param name="y"></param>
''' <param name="hWnd"></param>
''' <remarks>
''' Call to popup the ToolbarMenu on the display of the ToolbarControl's buddy. 
''' For example, if AxToolbarControl1 is buddied to AxMapControl1 use the following 
''' code from one of the MapControl's mouse events:
''' PopupToolbarMenu(e.x, e.y, AxMapControl1.hWnd)
''' </remarks>
Private Sub PopupToolbarMenu(ByVal x As System.Int32, ByVal y As System.Int32, ByVal hWnd As System.Int32)

  m_ToolbarMenu.PopupMenu(x, y, hWnd)

End Sub

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