private void TOCContextMenuItem_RemoveLayer(object sender, EventArgs e) { ESRI.ArcGIS.Controls.esriTOCControlItem pItem = ESRI.ArcGIS.Controls.esriTOCControlItem.esriTOCControlItemNone; ESRI.ArcGIS.Carto.ILayer pLayer = null; ESRI.ArcGIS.Carto.IBasicMap pMap = null; object pIndex = null; object pOther = null; TOCControl.GetSelectedItem(ref pItem, ref pMap, ref pLayer, ref pIndex, ref pOther); if (pLayer != null) { MainMap.Map.DeleteLayer(pLayer); } }
private void axTOCControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.ITOCControlEvents_OnMouseDownEvent e) { IBasicMap pMap = null; ILayer pLayer = null; object unk = null, data = null; ESRI.ArcGIS.Controls.esriTOCControlItem pItem = ESRI.ArcGIS.Controls.esriTOCControlItem.esriTOCControlItemNone; try { axTOCControl1.HitTest(e.x, e.y, ref pItem, ref pMap, ref pLayer, ref unk, ref data); } catch (Exception) { throw; } switch (e.button) { case 2: //右键 if (pItem == ESRI.ArcGIS.Controls.esriTOCControlItem.esriTOCControlItemMap) { axTOCControl1.SelectItem(pMap, null); } else if (pItem == ESRI.ArcGIS.Controls.esriTOCControlItem.esriTOCControlItemLayer) { axTOCControl1.SelectItem(pLayer, null); } axMapControl1.CustomProperty = pLayer; if (pItem == ESRI.ArcGIS.Controls.esriTOCControlItem.esriTOCControlItemMap) { // } if (pItem == ESRI.ArcGIS.Controls.esriTOCControlItem.esriTOCControlItemLayer) { var m_pMenuLayer = new ToolbarMenu(); m_pMenuLayer.AddItem(new BuildLineBuffer(), -1, 0, false, ESRI.ArcGIS.SystemUI.esriCommandStyles.esriCommandStyleTextOnly); m_pMenuLayer.AddItem(new ShowAttribute(), 1, 1, false, ESRI.ArcGIS.SystemUI.esriCommandStyles.esriCommandStyleTextOnly); m_pMenuLayer.SetHook(axMapControl1); m_pMenuLayer.PopupMenu(e.x, e.y, axTOCControl1.hWnd); } break; default: break; } }