Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

How can i create a context menu on ESRI 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. Thanks for your answers...

share|improve this question

2 Answers 2

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

share|improve this answer

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);
        }

    }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.