private void axTOCControl1_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e) { //make sure that the user right clicked if (2 != e.button) { return; } //use HitTest in order to test whether the user has selected a featureLayer esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone; IBasicMap map = null; ILayer layer = null; object other = null; object index = null; //do the HitTest axTOCControl1.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index); //Determine what kind of item has been clicked on if (null == layer || !(layer is IFeatureLayer)) { return; } //set the featurelayer as the custom property of the MapControl axMapControl1.CustomProperty = layer; //popup a context menu with a 'Properties' command m_contextMenu.PopupMenu(e.x, e.y, axTOCControl1.hWnd); }
// 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(); } }
private void axTOCControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.ITOCControlEvents_OnMouseDownEvent e) { //Exit if not right mouse button if (e.button != 2) { return; } IBasicMap map = new MapClass(); ILayer layer = new FeatureLayerClass(); object other = new Object(); object index = new Object(); esriTOCControlItem item = new esriTOCControlItem(); //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); //QI to IFeatureLayer and IGeoFeatuerLayer interface if (layer == null) { return; } IFeatureLayer featureLayer = layer as IFeatureLayer; if (featureLayer == null) { return; } IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer)featureLayer; ISimpleRenderer simpleRenderer = (ISimpleRenderer)geoFeatureLayer.Renderer; //Create the form with the SymbologyControl frmSymbol symbolForm = new frmSymbol(); //Get the IStyleGalleryItem IStyleGalleryItem styleGalleryItem = null; //Select SymbologyStyleClass based upon feature type switch (featureLayer.FeatureClass.ShapeType) { case esriGeometryType.esriGeometryPoint: styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassMarkerSymbols, simpleRenderer.Symbol); break; case esriGeometryType.esriGeometryPolyline: styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassLineSymbols, simpleRenderer.Symbol); break; case esriGeometryType.esriGeometryPolygon: styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassFillSymbols, simpleRenderer.Symbol); break; } //Release the form symbolForm.Dispose(); this.Activate(); if (styleGalleryItem == null) { return; } //Create a new renderer simpleRenderer = new SimpleRendererClass(); //Set its symbol from the styleGalleryItem simpleRenderer.Symbol = (ISymbol)styleGalleryItem.Item; //Set the renderer into the geoFeatureLayer geoFeatureLayer.Renderer = (IFeatureRenderer)simpleRenderer; //Fire contents changed event that the TOCControl listens to axPageLayoutControl1.ActiveView.ContentsChanged(); //Refresh the display axPageLayoutControl1.Refresh(esriViewDrawPhase.esriViewGeography, null, null); }