欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

基于ArcGIS Engine的TOCControl右键菜单的两种实现方法

程序员文章站 2024-01-29 10:25:22
...

      基于Arcgis Engine的二次开发,TOCControl和MapControl的右键菜单比较常用,本篇博客仅讲述一下TOCControl的右键菜单的两种实现方法,MapControl的右键菜单类似。

方法一:使用contextMenuStrip实现,可在TOCControl的OnMouseDown事件中填写

    if(e.button!=2) return;
     esriTOCControlItem pItem = esriTOCControlItem.esriTOCControlItemNone;
     IBasicMap pMap = null;
     ILayer pLayer = null;
     IFeatureLayer pTocFeatureLayer = null;
     object unk = null;
     object data = null;
     axTOCControl1.HitTest(e.x, e.y, ref pItem, ref pMap, ref pLayer, ref unk, ref data);
     pTocFeatureLayer = pLayer as IFeatureLayer;
     if (pItem == esriTOCControlItem.esriTOCControlItemLayer && pTocFeatureLayer != null)
     {
           contextMenuStrip1.Show(Control.MousePosition);
     }

方法二:使用ToolbarMenu实现,可在TOCControl的OnMouseDown事件中填写

if (e.button == 2)              
{
   esriTOCControlItem pItem = esriTOCControlItem.esriTOCControlItemNone;
   IBasicMap pMap = null;
   ILayer pLayer = null;
   object unk = null;
   object data = null;
   axTOCControl1.HitTest(e.x, e.y, ref pItem, ref pMap, ref pLayer,ref unk,ref data);
   if (pItem == esriTOCControlItem.esriTOCControlItemLayer )
    {
        IToolbarMenu pToolbarMenu=new ToolbarMenu(); 
        pToolbarMenu.AddItem(new ControlsMapViewMenu(),0,0,true,
                   esriCommandStyles.esriCommandStyleIconAndText); 
        pToolbarMenu.SetHook(axMapControl1.Object);  
        pToolbarMenu.PopupMenu(e.x,e.y,axTOCControl1.hWnd);           
         
    }
}