private void MainForm_Load(object sender, EventArgs e) { //get the MapControl m_mapControl = (IMapControl3)axMapControl1.Object; //disable the Save menu (since there is no document yet) menuSaveDoc.Enabled = false; if (m_mapControl.CheckMxFile(mxdPath)) { m_mapControl.LoadMxFile(mxdPath); } }
/// <summary> /// Occurs when this tool is clicked /// </summary> public override void OnClick() { // TODO: Add OpenTool.OnClick implementation OpenFileDialog OpenMXD = new OpenFileDialog(); //可实例化类 OpenMXD.Title = "打开地图"; // OpenFileDialog类的属性Title OpenMXD.Multiselect = false; OpenMXD.Filter = "Map Documents (*.mxd)|*.mxd"; if (OpenMXD.ShowDialog() == DialogResult.OK) //ShowDialog是类的方法 { string docName = OpenMXD.FileName; IMapDocument pMapDoc = new MapDocumentClass(); if (pMapDoc.get_IsPresent(docName) && !pMapDoc.get_IsPasswordProtected(docName)) { pMapControl.LoadMxFile(OpenMXD.FileName, null, null); pMapControl.ActiveView.Refresh(); pMapDoc.Close(); } } }