可以直接使用 axMapControl1.DrawShape 方法来实现~!
也可以通过 IScreenDisplay 接口的方法来实现!~
通过比较,只是后面实现的部分不同,前面都是相同的!
---------------------------------------------------------------------------------------------------------
●·● 实现:在 MapControl 上绘制几何图形(IGraphicsContainer,几何:圆):
普通的图形,可以直接向下面一样实现!
ISimpleLineSymbol pLineSym = new SimpleLineSymbol();
IRgbColor pColor = new RgbColor();
pColor.Red = 11;
pColor.Green = 120;
pColor.Blue = 233;
pLineSym.Color = pColor;
pLineSym.Style = esriSimpleLineStyle.esriSLSSolid;
pLineSym.Width = 2;
IPolyline pLine = axMapControl1.TrackLine() as IPolyline;
object symbol = pLineSym as object;
axMapControl1.DrawShape(pLine, ref symbol);
也可以通过 IScreenDisplay 接口的方法来实现!~
ISimpleLineSymbol pLineSym = new SimpleLineSymbol();
IRgbColor pColor = new RgbColor();
pColor.Red = 11;
pColor.Green = 120;
pColor.Blue = 233;
pLineSym.Color = pColor;
pLineSym.Style = esriSimpleLineStyle.esriSLSSolid;
pLineSym.Width = 2;
IPolyline pLine = axMapControl1.TrackLine() as IPolyline;
IScreenDisplay pScreenDisplay = axMapControl1.ActiveView.ScreenDisplay;
pScreenDisplay.StartDrawing(pScreenDisplay.hDC, 1);
pScreenDisplay.SetSymbol(pLineSym as ISymbol);
pScreenDisplay.DrawPolyline(pLine);
pScreenDisplay.FinishDrawing();
通过比较,只是后面实现的部分不同,前面都是相同的!
---------------------------------------------------------------------------------------------------------
●·● 实现:在 MapControl 上绘制几何图形(IGraphicsContainer,几何:圆):
普通的图形,可以直接向下面一样实现!
m_ActiveView = m_hookHelper.ActiveView;
m_Map = m_hookHelper.FocusMap;
IScreenDisplay pScreenDisplay = m_ActiveView.ScreenDisplay;
IRubberBand pRubberPolygon = new RubberPolygonClass();
ISimpleFillSymbol pFillSymbol = new SimpleFillSymbolClass();
pFillSymbol.Color = getRGB(255, 255, 0);
IPolygon pPolygon = pRubberPolygon.TrackNew(pScreenDisplay, (ISymbol)pFillSymbol) as IPolygon;
pFillSymbol.Style = esriSimpleFillStyle.esriSFSDiagonalCross;
pFillSymbol.Color = getRGB(0, 255, 255);
IFillShapeElement pPolygonEle = new PolygonElementClass();
pPolygonEle.Symbol = pFillSymbol;
IElement pEle = pPolygonEle as IElement;
pEle.Geometry = pPolygon;
IGraphicsContainer pGraphicsContainer = m_Map as IGraphicsContainer;
pGraphicsContainer.AddElement(pEle, 0);
m_ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
画圆比较特殊,因为没有圆这个现成的几何体,因此要转换,如下所示:
m_ActiveView = m_hookHelper.ActiveView;
m_Map = m_hookHelper.FocusMap;
IScreenDisplay pScreenDisplay = m_ActiveView.ScreenDisplay;
IRubberBand pRubberCircle = new RubberCircleClass();
ISimpleFillSymbol pFillSymbol = new SimpleFillSymbolClass();
pFillSymbol.Color = getRGB(255, 255, 0);
IGeometry pCircle = pRubberCircle.TrackNew(pScreenDisplay, (ISymbol)pFillSymbol) as IGeometry;
IPolygon pPolygon = new PolygonClass(); //空的多边形
ISegmentCollection pSegmentCollection = pPolygon as ISegmentCollection; //段集合
ISegment pSegment = pCircle as ISegment; //将圆赋值给段
object missing = Type.Missing; //显示默认值
pSegmentCollection.AddSegment(pSegment, ref missing, ref missing); //给空多边形加入圆
pFillSymbol.Style = esriSimpleFillStyle.esriSFSDiagonalCross;
pFillSymbol.Color = getRGB(0, 255, 255);
IFillShapeElement pPolygonEle = new PolygonElementClass();
pPolygonEle.Symbol = pFillSymbol;
IElement pEle = pPolygonEle as IElement;
pEle.Geometry = pPolygon;
IGraphicsContainer pGraphicsContainer = m_Map as IGraphicsContainer;
pGraphicsContainer.AddElement(pEle, 0);
m_ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);