![]()
1 using ESRI.ArcGIS.Carto;
2 using ESRI.ArcGIS.Controls;
3 using ESRI.ArcGIS.Display;
4 using ESRI.ArcGIS.esriSystem;
5 using System;
6 using System.Collections.Generic;
7 using System.ComponentModel;
8 using System.Data;
9 using System.Drawing;
10 using System.Linq;
11 using System.Text;
12 using System.Threading.Tasks;
13 using System.Windows.Forms;
14
15 namespace Ch02Ex08
16 {
17 public partial class Form1 : Form
18 {
19 public Form1()
20 {
21 InitializeComponent();
22 }
23 //加载地图文档
24 private void loadMapDocument()
25 {
26 System.Windows.Forms.OpenFileDialog openFileDialog;
27 openFileDialog = new OpenFileDialog();
28 openFileDialog.Title = "打开地图文档";
29 openFileDialog.Filter = "map documents(*.mxd)|*.mxd";
30 openFileDialog.ShowDialog();
31 string filePath = openFileDialog.FileName;
32 if (axMapControl1.CheckMxFile(filePath))
33 {
34 axMapControl1.MousePointer = esriControlsMousePointer.esriPointerHourglass;
35 axMapControl1.LoadMxFile(filePath, 0, Type.Missing);
36 axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
37 }
38 else
39 {
40 MessageBox.Show(filePath + "不是有效的地图文档");
41 }
42 }
43 private void copyToPageLayout()
44 {
45 IObjectCopy objectCopy = new ObjectCopy();
46 object copyFromMap = axMapControl1.Map;
47 object copyMap = objectCopy.Copy(copyFromMap);
48 object copyToMap = axPageLayoutControl1.ActiveView.FocusMap;
49 objectCopy.Overwrite(copyMap, ref copyToMap);
50 }
51
52 private void axMapControl1_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e)
53 {
54 copyToPageLayout();
55 }
56
57 private void axMapControl1_OnAfterScreenDraw(object sender, IMapControlEvents2_OnAfterScreenDrawEvent e)
58 {
59 IActiveView activeView = (IActiveView)axPageLayoutControl1.ActiveView.FocusMap;
60 IDisplayTransformation displayTransformation = activeView.ScreenDisplay.DisplayTransformation;
61 displayTransformation.VisibleBounds = axMapControl1.Extent;
62 axPageLayoutControl1.ActiveView.Refresh();
63 copyToPageLayout();
64 }
65
66 private void Form1_Click(object sender, EventArgs e)
67 {
68 loadMapDocument();
69 }
70 }
71 }