基于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);
}
}
上一篇: Wagtail 教程 4:自动生成文章右侧TOC导航
下一篇: 2020-12-15