基于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)
{
esr