1 //添加图层文件 2 private void addLayerFile() 3 { 4 System.Windows.Forms.OpenFileDialog openFileDialog; 5 openFileDialog = new OpenFileDialog(); 6 openFileDialog.Title = "打开图层文件"; 7 openFileDialog.Filter = "map documents(*.lyr)|*.lyr"; 8 openFileDialog.ShowDialog(); 9 string filePath = openFileDialog.FileName; 10 try 11 { 12 axMapControl1.AddLayerFromFile(filePath); 13 } 14 catch (Exception e) 15 { 16 MessageBox.Show("添加图层失败!!!" + e.ToString()); 17 } 18 } 19 //添加shape文件 20 private void addShapeFile() 21 { 22 System.Windows.Forms.OpenFileDialog openFileDialog; 23 openFileDialog = new OpenFileDialog(); 24 openFileDialog.Title = "打开图层文件"; 25 openFileDialog.Filter = "map documents(*.shp)|*.shp"; 26 openFileDialog.ShowDialog(); 27 28 try 29 { 30 FileInfo fileInfo = new FileInfo(openFileDialog.FileName); 31 string path = openFileDialog.FileName.Substring(0, openFileDialog.FileName.Length - fileInfo.Name.Length); 32 axMapControl1.AddShapeFile(path, fileInfo.Name); 33 } 34 catch (Exception e) 35 { 36 MessageBox.Show("添加图层失败!!!" + e.ToString()); 37 } 38 } 39 //删除图层 40 private void deleteLayer() 41 { 42 try 43 { 44 //删除地图中所有图层 45 for (int i = axMapControl1.LayerCount - 1; i >= 0; i--) 46 { 47 axMapControl1.DeleteLayer(i); 48 } 49 } 50 catch (Exception e) 51 { 52 MessageBox.Show("删除图层失败!!!" + e.ToString()); 53 } 54 } 55 //移动图层 56 private void moveLayer() 57 { 58 if (axMapControl1.LayerCount > 0) 59 { 60 try 61 { 62 //将最下层图层文件移动到最上层 63 axMapControl1.MoveLayerTo(axMapControl1.LayerCount - 1, 0); 64 } 65 catch (Exception e) 66 { 67 MessageBox.Show("移动图层失败!!!" + e.ToString()); 68 } 69 } 70 }