(1)使用 contextMenuStrip 实现 可在toc的OnMouseDown事件中写
if (e.button != 2) return;
esriTOCControlItem pItem = esriTOCControlItem.esriTOCControlItemNone;
IBasicMap pMap = null;
ILayer pLayer = null;
object pOther = new object();
object pIndex = new object();
axTOCControl1.HitTest(e.x, e.y, ref pItem, ref pMap, ref pLayer, ref pOther, ref pIndex);
if (pItem == esriTOCControlItem.esriTOCControlItemLayer)
{
System.Drawing.Point p = new System.Drawing.Point();
p.X = e.x;
p.Y = e.y;
contextMenuStrip1.Show(axTOCControl1, p);
}
(2)使用ToolbarMenu实现 可在toc的OnMouseDown事件中写
if (e.button == 2)
{
IBasicMap pMap = null;
ILayer pLayer = null;
object pOther = null;
esriTOCControlItem pItem = esriTOCControlItem.esriTOCControlItemNone;
object pIndex = null;
axTOCControl1.HitTest(e.x, e.y,ref pItem,ref pMap,ref pLayer,ref pOther,ref pIndex);
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);
}
}