// Show the TOC context menu when an NALayer is right-clicked on private void axTOCControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.ITOCControlEvents_OnMouseDownEvent e) { if (e.button != 2) { return; } esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone; IBasicMap map = null; ILayer layer = null; object other = null; object index = null; //Determine what kind of item has been clicked on axTOCControl1.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index); // Only implemented a context menu for NALayers. Exit if the layer is anything else. if ((layer as INALayer) == null) { return; } axTOCControl1.SelectItem(layer); // Set the layer into the CustomProperty. // This is used by the other commands to know what layer was right-clicked on // in the table of contents. axMapControl1.CustomProperty = layer; //Popup the correct context menu and update the TOC when it's done. if (item == esriTOCControlItem.esriTOCControlItemLayer) { m_menuLayer.PopupMenu(e.x, e.y, axTOCControl1.hWnd); ITOCControl toc = axTOCControl1.Object as ITOCControl; toc.Update(); } }