1 using ESRI.ArcGIS.Carto; 2 using ESRI.ArcGIS.Controls; 3 using ESRI.ArcGIS.Display; 4 using ESRI.ArcGIS.esriSystem; 5 using ESRI.ArcGIS.Geometry; 6 using System; 7 using System.Collections.Generic; 8 using System.ComponentModel; 9 using System.Data; 10 using System.Drawing; 11 using System.Linq; 12 using System.Text; 13 using System.Threading.Tasks; 14 using System.Windows.Forms; 15 16 namespace Ch02Ex09 17 { 18 public partial class Form1 : Form 19 { 20 public Form1() 21 { 22 InitializeComponent(); 23 } 24 int flag = 0; 25 IMapDocument mapDocumentClass ; 26 private void button1_Click(object sender, EventArgs e) 27 {//设置边框 28 axSymbologyControl1.StyleClass = esriSymbologyStyleClass.esriStyleClassBorders; 29 } 30 private void button2_Click(object sender, EventArgs e) 31 {//设置阴影 32 axSymbologyControl1.StyleClass = esriSymbologyStyleClass.esriStyleClassShadows; 33 } 34 //加载地图文档 35 private void loadMapDocument() 36 { 37 System.Windows.Forms.OpenFileDialog openFileDialog; 38 openFileDialog = new OpenFileDialog(); 39 openFileDialog.Title = "打开地图文档"; 40 openFileDialog.Filter = "map documents(*.mxd)|*.mxd"; 41 openFileDialog.ShowDialog(); 42 mapDocumentClass = new MapDocument(); 43 string filePath = openFileDialog.FileName; 44 try 45 { 46 mapDocumentClass.Open(filePath, ""); 47 axPageLayoutControl1.PageLayout = mapDocumentClass.PageLayout; 48 axPageLayoutControl1.Refresh(); 49 } 50 catch (Exception ex) 51 { 52 MessageBox.Show(ex.ToString()); 53 } 54 } 55 56 private void Form1_Click(object sender, EventArgs e) 57 { 58 loadMapDocument(); 59 Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\ESRI\CoreRuntime", true); 60 // axSymbologyControl1.LoadStyleFile(regKey.GetValue("InstallDir") + "\Styles\ESRI.ServerStyle"); 61 axSymbologyControl1.GetStyleClass(esriSymbologyStyleClass.esriStyleClassBackgrounds).Update(); 62 axSymbologyControl1.GetStyleClass(esriSymbologyStyleClass.esriStyleClassBorders).Update(); 63 axSymbologyControl1.GetStyleClass(esriSymbologyStyleClass.esriStyleClassShadows).Update(); 64 } 65 66 private void button3_Click(object sender, EventArgs e) 67 {//设置背景 68 axSymbologyControl1.StyleClass = esriSymbologyStyleClass.esriStyleClassBackgrounds; 69 } 70 71 private void button4_Click(object sender, EventArgs e) 72 {//设置网络 73 IMap map; 74 IActiveView activeView; 75 activeView = axPageLayoutControl1.PageLayout as IActiveView; 76 map = activeView.FocusMap; 77 78 IMapGrid mapGrid; 79 IMeasuredGrid measuredGrid; 80 measuredGrid = new MeasuredGrid() as IMeasuredGrid; 81 mapGrid = measuredGrid as IMapGrid; 82 measuredGrid.FixedOrigin = true; 83 measuredGrid.Units = map.MapUnits; 84 measuredGrid.XIntervalSize = 10; 85 measuredGrid.YIntervalSize = 10; 86 measuredGrid.XOrigin = -180; 87 measuredGrid.YOrigin = -90; 88 89 IProjectedGrid projectedGrid; 90 projectedGrid = measuredGrid as IProjectedGrid; 91 projectedGrid.SpatialReference = map.SpatialReference; 92 mapGrid.Name = "Measured Grid"; 93 IMapFrame mapFrame; 94 IGraphicsContainer graphicsContainer; 95 graphicsContainer = activeView as IGraphicsContainer; 96 mapFrame = graphicsContainer.FindFrame(map) as IMapFrame; 97 IMapGrids mapGrids = mapFrame as IMapGrids; 98 mapGrids.AddMapGrid(mapGrid); 99 activeView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null); 100 } 101 102 private void button6_Click(object sender, EventArgs e) 103 {//添加文字 104 IActiveView activeView; 105 IGraphicsContainer graphicsContainer; 106 ITextElement textElement; 107 ITextSymbol textSymbol; 108 IRgbColor color; 109 IElement element; 110 IEnvelope envelope; 111 112 activeView = axPageLayoutControl1.PageLayout as IActiveView; 113 envelope = new Envelope() as IEnvelope; 114 envelope.PutCoords(0, 0, 5, 5); 115 textElement = new TextElement() as ITextElement; 116 element = textElement as IElement; 117 element.Geometry = envelope; 118 textElement.Text = "我的地图"; 119 textSymbol = new TextSymbol(); 120 color = new RgbColor(); 121 color.Green = 255; 122 color.Blue = 255; 123 color.Red = 0; 124 textSymbol.Color = color as IColor; 125 textSymbol.Size = 30; 126 textElement.Symbol = textSymbol; 127 graphicsContainer = activeView as IGraphicsContainer; 128 graphicsContainer.AddElement(element, 0); 129 axPageLayoutControl1.Refresh(); 130 //axPageLayoutControl1.ActiveView.PartialRefresh (esriViewDrawPhase.esriViewBackground ,null ,null ); 131 } 132 133 private void button5_Click(object sender, EventArgs e) 134 { 135 //添加图例 136 UID uid; 137 IEnvelope envelope; 138 IMapSurround mapSurround; 139 IGraphicsContainer graphicsContainer; 140 IMapFrame mapFrame; 141 IMapSurroundFrame mapSurroundFrame; 142 IElement element; 143 ITrackCancel trackCancel; 144 145 uid = new UID(); 146 uid.Value = "esriCarto.legend"; 147 envelope = new Envelope() as IEnvelope; 148 envelope.PutCoords(1, 1, 2, 2); 149 graphicsContainer = axPageLayoutControl1.PageLayout as IGraphicsContainer; 150 mapFrame = graphicsContainer.FindFrame(axPageLayoutControl1.ActiveView.FocusMap) as IMapFrame; 151 152 mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null); 153 mapSurroundFrame.MapSurround.Name = "图例"; 154 element = mapSurroundFrame as IElement; 155 element.Geometry = envelope; 156 element.Activate(axPageLayoutControl1.ActiveView.ScreenDisplay); 157 trackCancel = new CancelTracker(); 158 element.Draw(axPageLayoutControl1.ActiveView.ScreenDisplay, trackCancel); 159 graphicsContainer.AddElement(element, 0); 160 axPageLayoutControl1.Refresh(); 161 } 162 163 private void button7_Click(object sender, EventArgs e) 164 { 165 //文字比例尺 166 UID uid; 167 IEnvelope envelope; 168 IMapSurround mapSurround; 169 IGraphicsContainer graphicsContainer; 170 IMapFrame mapFrame; 171 IMapSurroundFrame mapSurroundFrame; 172 IElement element; 173 ITrackCancel trackCancel; 174 uid = new UID(); 175 uid.Value = "esriCarto.ScaleText"; 176 envelope = new Envelope() as IEnvelope; 177 envelope.PutCoords(1, 1, 2, 2); 178 graphicsContainer = axPageLayoutControl1.PageLayout as IGraphicsContainer; 179 mapFrame = graphicsContainer.FindFrame(axPageLayoutControl1.ActiveView.FocusMap) as IMapFrame; 180 mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null); 181 element = mapSurroundFrame as IElement; 182 element.Geometry = envelope; 183 element.Activate(axPageLayoutControl1.ActiveView.ScreenDisplay); 184 trackCancel = new CancelTracker(); 185 element.Draw(axPageLayoutControl1.ActiveView.ScreenDisplay, trackCancel); 186 graphicsContainer.AddElement(element, 0); 187 axPageLayoutControl1.Refresh(); 188 } 189 190 private void button8_Click(object sender, EventArgs e) 191 { 192 //图形比例尺 193 194 UID uid; 195 IEnvelope envelope; 196 IMapSurround mapSurround; 197 IGraphicsContainer graphicsContainer; 198 IMapFrame mapFrame; 199 IMapSurroundFrame mapSurroundFrame; 200 IElement element; 201 ITrackCancel trackCancel; 202 uid = new UID(); 203 uid.Value = "esriCarto.ScaleLine"; 204 envelope = new Envelope() as IEnvelope; 205 envelope.PutCoords(1, 1, 10, 2); 206 graphicsContainer = axPageLayoutControl1.PageLayout as IGraphicsContainer; 207 mapFrame = graphicsContainer.FindFrame(axPageLayoutControl1.ActiveView.FocusMap) as IMapFrame; 208 mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null); 209 element = mapSurroundFrame as IElement; 210 element.Geometry = envelope; 211 element.Activate(axPageLayoutControl1.ActiveView.ScreenDisplay); 212 trackCancel = new CancelTracker(); 213 element.Draw(axPageLayoutControl1.ActiveView.ScreenDisplay, trackCancel); 214 graphicsContainer.AddElement(element, 0); 215 axPageLayoutControl1.Refresh(); 216 } 217 218 private void button9_Click(object sender, EventArgs e) 219 { 220 axPageLayoutControl1.Extent = axPageLayoutControl1.FullExtent; 221 axPageLayoutControl1.Refresh(); 222 } 223 224 private void button10_Click(object sender, EventArgs e) 225 { 226 axPageLayoutControl1.MousePointer = esriControlsMousePointer.esriPointerZoomIn; 227 flag = 2; 228 } 229 230 private void button11_Click(object sender, EventArgs e) 231 { 232 axPageLayoutControl1.MousePointer = esriControlsMousePointer.esriPointerZoomOut; 233 flag = 1; 234 } 235 236 237 } 238 }