private void cmdLoadData_Click(object sender, System.EventArgs e) { openFileDialog1.Title = "Browse Map Document"; openFileDialog1.Filter = "Map Documents (*.mxd)|*.mxd"; openFileDialog1.ShowDialog(); //Exit if no map document is selected string sFilePath = openFileDialog1.FileName; if (sFilePath == "") { return; } //Validate and load map document if (axMapControl1.CheckMxFile(sFilePath) == true) { axMapControl1.LoadMxFile(sFilePath, Type.Missing, ""); //Enabled MapControl axMapControl1.Enabled = true; } else { MessageBox.Show(sFilePath + " is not a valid ArcMap document"); return; } //Add the layer names to combo cboDataLayer.Items.Clear(); for (int i = 0; i <= axMapControl1.LayerCount - 1; i++) { cboDataLayer.Items.Insert(i, axMapControl1.get_Layer(i).Name); } //Select first layer in control cboDataLayer.SelectedIndex = 0; //Enable controls if disabled if (chkShowTips.Enabled == false) { chkShowTips.Enabled = true; } if (chkTransparent.Enabled == false) { chkTransparent.Enabled = true; } if (cboDataLayer.Enabled == false) { cboDataLayer.Enabled = true; } if (cboDataField.Enabled == false) { cboDataField.Enabled = true; } }
public static void NewMapDoc(Control.ControlCollection controls, ESRI.ArcGIS.Controls.AxMapControl mainMapControl) { try { //实例化AxMapControl控件,并加入Form的Controls ESRI.ArcGIS.Controls.AxMapControl axMapControl = new ESRI.ArcGIS.Controls.AxMapControl(); ((System.ComponentModel.ISupportInitialize)(axMapControl)).BeginInit(); controls.Add(axMapControl); ((System.ComponentModel.ISupportInitialize)(axMapControl)).EndInit(); //实例化SaveFileDialog控件 SaveFileDialog pSaveFileDialog = new SaveFileDialog(); pSaveFileDialog.Title = "输入需要新建地图文档的名称"; pSaveFileDialog.Filter = "地图文件(*.mxd)|*.mxd"; pSaveFileDialog.OverwritePrompt = true; pSaveFileDialog.RestoreDirectory = true; if (pSaveFileDialog.ShowDialog() == DialogResult.OK) {//保存地图文档 string filename = pSaveFileDialog.FileName; IMapDocument pMapDocument = new MapDocumentClass(); pMapDocument.New(filename); axMapControl.Map = pMapDocument.get_Map(0); axMapControl.DocumentFilename = pMapDocument.DocumentFilename; pMapDocument.Close(); mainMapControl.LoadMxFile(filename); mainMapControl.Refresh(); MessageBox.Show("新建地图文档成功!", "信息提示", MessageBoxButtons.OK); return; } else { return; } } catch (Exception exc) { MessageBox.Show("新建地图文档失败!" + exc.Message, "信息提示", MessageBoxButtons.OK); return; } }