//新建地图文档 public void NewMapDoc(AxMapControl axMapControl1) { DialogResult dialogResult = MessageBox.Show("保存文件?", "关闭文件", MessageBoxButtons.YesNoCancel); if (dialogResult == DialogResult.Yes) { SaveDocument(axMapControl1); SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Title = "新建地图文档"; saveFileDialog1.Filter = "地图文档(*.mxd)|*.mxd"; saveFileDialog1.ShowDialog(); string filePath = saveFileDialog1.FileName; //地图文档路径 mapDocument.New(filePath); //新建 mapDocument.Open(filePath, ""); //打开 axMapControl1.Map = mapDocument.get_Map(0); } if (dialogResult == DialogResult.No) { SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Title = "新建地图文档"; saveFileDialog1.Filter = "地图文档(*.mxd)|*.mxd"; saveFileDialog1.ShowDialog(); string filePath = saveFileDialog1.FileName; //地图文档路径 mapDocument.New(filePath); //新建 mapDocument.Open(filePath, ""); //打开 axMapControl1.Map = mapDocument.get_Map(0); } if (dialogResult == DialogResult.Cancel) { return; } }
private void newToolStripMenuItem_Click(object sender, EventArgs e) { string filter = "Map document (*.mxd)|*.mxd"; saveFileDialog1.Filter = filter; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { string filename = saveFileDialog1.FileName; //mxdocument = new MxDocumentClass(); mapdocument = new MapDocument(); mapdocument.New(filename); mapdocument.SaveAs(filename); mapdocument.Close(); LoadMxdFile(filename); } }
public static void OperateMapDoc(AxMapControl axMapControl1, AxMapControl axMapControl2, string strOperateType) { OpenFileDialog OpenFileDialog = new OpenFileDialog(); SaveFileDialog SaveFileDialog = new SaveFileDialog(); OpenFileDialog.Filter = "地图文档文件(*.mxd)|*.mxd"; SaveFileDialog.Filter = "地图文档文件(*.mxd)|*.mxd"; string strDocFileN = string.Empty; pMapDocument = new MapDocumentClass(); switch (strOperateType) { case "NewDoc": { SaveFileDialog.Title = "输入需要新建地图文档的名称"; SaveFileDialog.ShowDialog(); strDocFileN = SaveFileDialog.FileName; if (strDocFileN == string.Empty) return; pMapDocument.New(strDocFileN); pMapDocument.Open(strDocFileN, ""); axMapControl1.Map = pMapDocument.get_Map(0); break; } case "OpenDoc": { OpenFileDialog.Title = "输入需要加载的地图文档"; OpenFileDialog.ShowDialog(); strDocFileN = OpenFileDialog.FileName; if (strDocFileN == string.Empty) return; pMapDocument.Open(strDocFileN, ""); for (int i = 0; i < pMapDocument.MapCount; i++) { axMapControl1.Map = pMapDocument.get_Map(i); //axMapControl2.Map = pMapDocument.get_Map(i); } axMapControl1.Refresh(); break; } case "SaveDoc": { if (pMapDocument.get_IsReadOnly(pMapDocument.DocumentFilename) == true) { MessageBox.Show("此地图为只读文档", "信息提示"); return; } pMapDocument.Save(pMapDocument.UsesRelativePaths, true); MessageBox.Show("保存成功!", "信息提示"); break; } case "SaveDocAS": { SaveFileDialog.Filter = "地图文档另存"; SaveFileDialog.ShowDialog(); strDocFileN = SaveFileDialog.FileName; if (strDocFileN == string.Empty) return; if (strDocFileN == pMapDocument.DocumentFilename) { pMapDocument.Save(pMapDocument.UsesRelativePaths, true); MessageBox.Show("保存成功!", "信息提示"); break; } else { pMapDocument.SaveAs(strDocFileN, true, true); MessageBox.Show("保存成功", "信息提示"); } break; } default: break; } }
public static void OperateMapDoc(AxMapControl axMapControl1, AxMapControl axMapControl2, string strOperateType) { OpenFileDialog OpenFileDialog = new OpenFileDialog(); SaveFileDialog SaveFileDialog = new SaveFileDialog(); OpenFileDialog.Filter = "地图文档文件(*.mxd)|*.mxd"; SaveFileDialog.Filter = "地图文档文件(*.mxd)|*.mxd"; string strDocFileN = string.Empty; pMapDocument = new MapDocumentClass(); switch (strOperateType) { case "NewDoc": { SaveFileDialog.Title = "输入需要新建地图文档的名称"; SaveFileDialog.ShowDialog(); strDocFileN = SaveFileDialog.FileName; if (strDocFileN == string.Empty) { return; } pMapDocument.New(strDocFileN); pMapDocument.Open(strDocFileN, ""); axMapControl1.Map = pMapDocument.get_Map(0); break; } case "OpenDoc": { OpenFileDialog.Title = "输入需要加载的地图文档"; OpenFileDialog.ShowDialog(); strDocFileN = OpenFileDialog.FileName; if (strDocFileN == string.Empty) { return; } pMapDocument.Open(strDocFileN, ""); for (int i = 0; i < pMapDocument.MapCount; i++) { axMapControl1.Map = pMapDocument.get_Map(i); //axMapControl2.Map = pMapDocument.get_Map(i); } axMapControl1.Refresh(); break; } case "SaveDoc": { if (pMapDocument.get_IsReadOnly(pMapDocument.DocumentFilename) == true) { MessageBox.Show("此地图为只读文档", "信息提示"); return; } pMapDocument.Save(pMapDocument.UsesRelativePaths, true); MessageBox.Show("保存成功!", "信息提示"); break; } case "SaveDocAS": { SaveFileDialog.Filter = "地图文档另存"; SaveFileDialog.ShowDialog(); strDocFileN = SaveFileDialog.FileName; if (strDocFileN == string.Empty) { return; } if (strDocFileN == pMapDocument.DocumentFilename) { pMapDocument.Save(pMapDocument.UsesRelativePaths, true); MessageBox.Show("保存成功!", "信息提示"); break; } else { pMapDocument.SaveAs(strDocFileN, true, true); MessageBox.Show("保存成功", "信息提示"); } break; } default: break; } }