声明toolbarmenu:

 IToolbarMenu pToolBarMenu = new ToolbarMenuClass();

在窗体load事件中初始化:

 pToolBarMenu.AddItem(new RemoveSelectedLayer1(), 0, -1, false, esriCommandStyles.esriCommandStyleTextOnly);
            pToolBarMenu.SetHook(axMapControl1.Object);

在toccontrol的onmousedown中获取选择项,主要用到customproperty属性:

 IBasicMap pBasicMap = null;
            ILayer pLayer = null;
            esriTOCControlItem pItem = esriTOCControlItem.esriTOCControlItemNone;
            object pUnk = null;
            object pData = null;
            if (e.button == 2)
            {
                
                
                axTOCControl1.HitTest(e.x, e.y, ref pItem, ref pBasicMap, ref pLayer, ref  pUnk, ref  pData);
               
            }
            if (pItem == esriTOCControlItem.esriTOCControlItemLayer)
            {
                axMapControl1.CustomProperty = pLayer;
                pToolBarMenu.PopupMenu(e.x, e.y, axTOCControl1.hWnd);
            }

在自定义的命令的click中操作:

   IMapControlDefault pMapControl = m_hookHelper.Hook as IMapControlDefault;
            IMap pMap = pMapControl.Map;
            ILayer pLayer = null;
            if (pMapControl.CustomProperty is ILayer)
            {
                pLayer = pMapControl.CustomProperty as ILayer;
            }
            pMap.DeleteLayer(pLayer);
            pMapControl.Refresh();

 

posted on 2014-11-26 15:18  小太  阅读(436)  评论(0编辑  收藏  举报