1. #region 生成点的三种方法
    2. /// <summary>
    3. /// 1.直接在mapcontrol视窗中画点,不能常驻
    4. /// </summary>
    5. private void DrawPoint()
    6. {
    7. //获得当前活动范围
    8. IActiveView pActiveView = axMapControl1.ActiveView;
    9. //开始画笔
    10. pActiveView.ScreenDisplay.StartDrawing(pActiveView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
    11. IPoint pPoint;
    12. //定义简单marker元素的标志
    13. ISimpleMarkerSymbol pSymbol = new SimpleMarkerSymbolClass();
    14. //设置颜色
    15. IRgbColor pRGBcolor = new RgbColorClass();
    16. pRGBcolor.Red = 255;
    17. pRGBcolor.Green = 255;
    18. pRGBcolor.Blue = 0;
    19. pSymbol.Color = pRGBcolor;
    20. //形状为圆形
    21. pSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;
    22. pSymbol.Size = 15;
    23. pSymbol.Angle = 270;
    24. //最后实现的时候要用ISymbol来实现,所以还是要做个转换
    25. ISymbol pPointSymbol = pSymbol as ISymbol;
    26. //该点是用来设置坐标的
    27. pPoint = new PointClass();
    28. pPoint.PutCoords(300, 300);
    29. pActiveView.ScreenDisplay.SetSymbol((ISymbol)pPointSymbol);
    30. pActiveView.ScreenDisplay.DrawPoint(pPoint);
    31. //结束画笔
    32. pActiveView.ScreenDisplay.UpdateWindow();
    33. pActiveView.ScreenDisplay.FinishDrawing();
    34. }
    35. /// <summary>
    36. /// 2.用element画点
    37. /// </summary>
    38. private void DrawPointElement(TopologyElement.Point p)
    39. {
    40. //首先要实现容器接口
    41. IGraphicsContainer pGraphicsContainer = axMapControl1.ActiveView as IGraphicsContainer;
    42. pGraphicsContainer.DeleteAllElements();//清空容器里面所有的元素
    43. //设置点的坐标
    44. IPoint pPoint = new PointClass();
    45. //pPoint.PutCoords(310, 310);
    46. //pPoint.PutCoords(310, 310);
    47. //pPoint.PutCoords(440475, 4655187);
    48. pPoint.X = p.X;
    49. pPoint.Y = p.Y;
    50. pPoint.X = 122.280739;
    51. pPoint.Y = 42.0464883;
    52. int forx = 0;
    53. int fory = 0;
    54. ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = axMapControl1.ActiveView.ScreenDisplay;
    55. ESRI.ArcGIS.Display.IDisplayTransformation displayTransformation = screenDisplay.DisplayTransformation;
    56. displayTransformation.FromMapPoint(pPoint, out forx, out fory);//输出的forx,fory为屏幕坐标
    57. //pPoint = this.axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(440475, 4655187);
    58. //pPoint.PutCoords(pPoint.X,pPoint.Y);
    59. //pPoint.PutCoords(122.280739, 42.0464883);
    60. //int x, y;
    61. //axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(pPoint, out x, out y);
    62. //axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(440475, 4655187);
    63. //IMarkerElement用来获得symbol属性
    64. IMarkerElement pMarkerElement = new MarkerElementClass();
    65. //用ISimpleMarkerSymbol来设置点的属性
    66. ISimpleMarkerSymbol pSymbol = new SimpleMarkerSymbolClass();
    67. IRgbColor pRGBcolor = new RgbColorClass();
    68. //设置颜色的时候使用计算机RGB
    69. //红色
    70. //pRGBcolor.Red = 255;
    71. //pRGBcolor.Green = 0;
    72. //pRGBcolor.Blue = 0;
    73. //黑色
    74. pRGBcolor.Red = 0;
    75. pRGBcolor.Green = 0;
    76. pRGBcolor.Blue = 0;
    77. //pRGBcolor.NullColor = true;
    78. pSymbol.Color = pRGBcolor;//红色
    79. //pSymbol.Color = pRGBcolor;//红色
    80. pMarkerElement.Symbol = pSymbol;
    81. //IElement用来获得Geometry属性
    82. IElement pElement = pMarkerElement as IElement;
    83. //把IPoint转换为为IGeoMetry也能实现
    84. //IGeometry pGeometry = pPoint as IGeometry;
    85. //pElement.Geometry = pGeometry;
    86. pElement.Geometry = pPoint;
    87. //在容器里添加元素
    88. pGraphicsContainer.AddElement(pElement, 0);
    89. pElement.Activate(axMapControl1.ActiveView.ScreenDisplay);
    90. axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pElement, null);
    91. }