1

How can i create a context menu on Arcgis Desktop.And after creating it,how can i use it while a base command is open and active.I use C# but i can understand visual basic.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jul 6, 2011 at 11:14

2 Answers 2

2

To instantiate it pass mapcontrol.Object as the parameter to the constructor.

using System;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Controls;
namespace MapLibrary.ContextMenus
{
 /// <summary>
 /// Context menu class for Engine applications.
 ///</summary>
 [Guid("d71c6409-7f8b-4f23-95ed-12ba0d461920")]
 [ClassInterface(ClassInterfaceType.None)]
 [ProgId("MapLibrary.ContextMenus.BasicContextMenu1")]
 public class BasicContextMenu1
 {
 private IToolbarMenu2 m_toolbarMenu = null;
 private bool m_beginGroupFlag = false;
 public BasicContextMenu1(object hook)
 {
 this.SetHook(hook); 
 }
 public void SetHook(object hook)
 {
 m_toolbarMenu = new ToolbarMenuClass();
 m_toolbarMenu.SetHook(hook);
 AddItem("esriControls.ControlsMapZoomInTool", -1);
 AddItem("esriControls.ControlsMapZoomOutTool", -1);
 AddItem("esriControls.ControlsMapFullExtentCommand", -1);
 AddItem("esriControls.ControlsMapPanTool", -1);
 AddItem("esriControls.ControlsMapIdentifyTool", -1);
 }
 public void PopupMenu(int X, int Y, int hWndParent)
 {
 if (m_toolbarMenu != null) m_toolbarMenu.PopupMenu(X, Y, hWndParent);
 }
 public IToolbarMenu2 ContextMenu
 {
 get
 {
 return m_toolbarMenu;
 }
 }
 private void BeginGroup()
 {
 m_beginGroupFlag = true;
 }
 private void AddItem(UID itemUID)
 {
 m_toolbarMenu.AddItem(itemUID.Value, itemUID.SubType, -1, m_beginGroupFlag, esriCommandStyles.esriCommandStyleIconAndText);
 m_beginGroupFlag = false; //Reset group flag
 }
 private void AddItem(string itemID, int subtype)
 {
 UID itemUID = new UIDClass();
 try
 {
 itemUID.Value = itemID;
 }
 catch
 {
 itemUID.Value = Guid.Empty.ToString("B");
 }
 if (subtype > 0)
 itemUID.SubType = subtype;
 AddItem(itemUID);
 }
 private void AddItem(Guid itemGuid, int subtype)
 {
 AddItem(itemGuid.ToString("B"), subtype);
 }
 private void AddItem(Type itemType, int subtype)
 {
 if (itemType != null) AddItem(itemType.GUID, subtype);
 }
 }
}
answered Jul 6, 2011 at 14:13
-1

There is at least a sample in your installation directory. I dont remember the name of the sample but you should have no difficulty in finding it

answered Jul 22, 2011 at 18:34

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.