1 using ESRI.ArcGIS.Display; 2 using ESRI.ArcGIS.Geometry; 3 using System; 4 using System.Collections.Generic; 5 using System.ComponentModel; 6 using System.Data; 7 using System.Drawing; 8 using System.Linq; 9 using System.Text; 10 using System.Threading.Tasks; 11 using System.Windows.Forms; 12 13 namespace Ch02Ex05 14 { 15 public partial class Form1 : Form 16 { 17 public Form1() 18 { 19 InitializeComponent(); 20 } 21 int flag = 0; 22 private void btnDrawLine_Click(object sender, EventArgs e) 23 { 24 flag = 1;//画线对象 25 } 26 27 private void btnDrawCircle_Click(object sender, EventArgs e) 28 { 29 flag = 2;//画圆对象 30 } 31 32 private void btnDrawRect_Click(object sender, EventArgs e) 33 { 34 flag = 3;//画矩形对象 35 } 36 37 private void btnDrawPolygon_Click(object sender, EventArgs e) 38 { 39 flag = 4;//画面对象 40 } 41 42 private void btnDrawText_Click(object sender, EventArgs e) 43 { 44 flag = 5;//画文本对象 45 } 46 private void DrawMapText(IGeometry geometry) 47 { 48 IRgbColor rgbColor = new RgbColor(); 49 rgbColor.Red = 225; 50 rgbColor.Blue = 0; 51 rgbColor.Green = 0; 52 ITextSymbol txtSymbol = new TextSymbol(); 53 txtSymbol.Color = rgbColor; 54 object symbol = txtSymbol; 55 axMapControl1.DrawText(geometry, "测试文本", ref symbol); 56 } 57 private void DrawMapShape(IGeometry pGeo) 58 { 59 IRgbColor rgbColor = new RgbColor(); 60 rgbColor.Red = 255; 61 rgbColor.Blue = 0; 62 rgbColor.Green = 255; 63 object symbol = null; 64 if (pGeo.GeometryType == esriGeometryType.esriGeometryPolyline) 65 { 66 ISimpleLineSymbol simpleLine = new SimpleLineSymbol(); 67 simpleLine.Color = rgbColor; 68 simpleLine.Width = 5; 69 symbol = simpleLine; 70 } 71 else 72 { 73 ISimpleFillSymbol fillSymbol = new SimpleFillSymbol(); 74 fillSymbol.Color = rgbColor; 75 symbol = fillSymbol; 76 } 77 axMapControl1.DrawShape(pGeo, ref symbol); 78 } 79 80 private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e) 81 { 82 IGeometry geometry = null; 83 if (flag == 1) 84 { 85 geometry = axMapControl1.TrackLine(); 86 } 87 else if (flag == 2) 88 { 89 geometry = axMapControl1.TrackCircle(); 90 } 91 else if (flag == 3) 92 { 93 geometry = axMapControl1.TrackRectangle(); 94 } 95 else if (flag == 4) 96 { 97 geometry = axMapControl1.TrackPolygon(); 98 } 99 else if (flag == 5) 100 { 101 IPoint point = new ESRI.ArcGIS.Geometry.Point(); 102 point.X = e.mapX; 103 point.Y = e.mapY; 104 geometry = point as IGeometry; 105 } 106 if (flag == 5) 107 { 108 DrawMapText(geometry); 109 } 110 if (flag >= 1 && flag <= 4) 111 { 112 DrawMapShape(geometry); 113 } 114 } 115 } 116 }