Beispiel #1
0
        public void DrawPolygon(ESRI.ArcGIS.Carto.IActiveView activeView)
        {
            if (activeView == null)
            {
                return;
            }

            ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = activeView.ScreenDisplay;
            screenDisplay.StartDrawing(screenDisplay.hDC, (System.Int16)ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache); // Explicit Cast
            ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
            rgbColor.Red = 255;

            ESRI.ArcGIS.Display.IColor            color            = rgbColor; // Implicit Cast
            ESRI.ArcGIS.Display.ISimpleFillSymbol simpleFillSymbol = new ESRI.ArcGIS.Display.SimpleFillSymbolClass();
            simpleFillSymbol.Color = color;

            ESRI.ArcGIS.Display.ISymbol     symbol     = simpleFillSymbol as ESRI.ArcGIS.Display.ISymbol; // Dynamic Cast
            ESRI.ArcGIS.Display.IRubberBand rubberBand = new ESRI.ArcGIS.Display.RubberPolygonClass();
            ESRI.ArcGIS.Geometry.IGeometry  geometry   = rubberBand.TrackNew(screenDisplay, symbol);
            screenDisplay.SetSymbol(symbol);
            screenDisplay.DrawPolygon(geometry);
            screenDisplay.FinishDrawing();
        }
Beispiel #2
0
        private void _drawPolygon()
        {
            if (this._axMapCtrl.ActiveView == null)
            {
                return;
            }

            ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = this._axMapCtrl.ActiveView.ScreenDisplay;

            // Constant.
            screenDisplay.StartDrawing(screenDisplay.hDC, (System.Int16)
                ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache); // Explicit cast.
            ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
            rgbColor.Red = 255;

            ESRI.ArcGIS.Display.IColor color = rgbColor; // Implicit cast.
            ESRI.ArcGIS.Display.ISimpleFillSymbol simpleFillSymbol = new
                ESRI.ArcGIS.Display.SimpleFillSymbolClass();
            simpleFillSymbol.Color = color;
            

            ESRI.ArcGIS.Display.ISymbol symbol = simpleFillSymbol as
                ESRI.ArcGIS.Display.ISymbol; // Dynamic cast.
            ESRI.ArcGIS.Display.IRubberBand rubberBand = new
                ESRI.ArcGIS.Display.RubberPolygonClass();
            ESRI.ArcGIS.Geometry.IGeometry geometry = rubberBand.TrackNew(screenDisplay,
                symbol);
            screenDisplay.SetSymbol(symbol);

            //screenDisplay.DrawPolygon(geometry);
            screenDisplay.FinishDrawing();
            
            PolygonElementClass element = new PolygonElementClass();
            element.Geometry = geometry;
            // Create lineSymbol
            ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass();
            // set color & style,....
            ESRI.ArcGIS.Display.IRgbColor lineColor = new ESRI.ArcGIS.Display.RgbColorClass();
            lineColor.Red = 255;
            lineSymbol.Color = lineColor;
            lineSymbol.Width = 3;

            // Create fillSymbol
            ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass();
            fillSymbol.Outline = lineSymbol;
            ESRI.ArcGIS.Display.IRgbColor fillColor = new ESRI.ArcGIS.Display.RgbColorClass();
            fillColor.Red = 255;
            fillColor.Green = 255;
            fillSymbol.Color = fillColor;
            fillSymbol.Style = esriSimpleFillStyle.esriSFSHollow;
            element.Symbol = fillSymbol;

            this._axMapCtrl.ActiveView.GraphicsContainer.AddElement(element, 0);
            
            //((IGraphicsContainerSelect)(this._axMapCtrl.ActiveView.GraphicsContainer)).SelectElement(element);
            this._axMapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

            if (this._polygonName != "")
            {
                element.Name = this._polygonName;
                this._polygonName = "";
            }
            /*
            else
            {
                int count = 0;
                IGraphicsContainer container = this._axMapCtrl.ActiveView.GraphicsContainer;
                container.Reset();
                while (container.Next() != null)
                {
                    count++;
                }
                element.Name = "Element " + count;
            }
            */
            if (PolygonDrawn != null)
            {
                PolygonDrawn(element.Name);
            }
        }