问题描述
请出现这种错误是为什么呢该如何改正呢usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingESRI.ArcGIS.ADF;usingESRI.ArcGIS.SystemUI;usingESRI.ArcGIS.Geometry;usingESRI.ArcGIS.Display;usingESRI.ArcGIS.Controls;usingESRI.ArcGIS.esriSystem;usingESRI.ArcGIS.Carto;namespaceGIS设计{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privatevoidForm1_Load(objectsender,EventArgse){}privatevoidMainForm_Load(objectsender,EventArgse){//将主窗体放大到整个屏幕this.Size=Screen.PrimaryScreen.WorkingArea.Size;this.Location=newSystem.Drawing.Point(0,0);//将axToolbarControl和axTOCControl与axMapControl2绑定!axToolbarControl1.SetBuddyControl(axMapControl2);axTOCControl1.SetBuddyControl(axMapControl2);}privatevoidtabControl1_TabIndexChanged(objectsender,EventArgse){}privatevoidtabControl1_SelectedIndexChanged(objectsender,EventArgse){if(tabControl1.SelectedIndex==0){axToolbarControl1.SetBuddyControl(axMapControl2);axTOCControl1.SetBuddyControl(axMapControl2);}else{axToolbarControl1.SetBuddyControl(axPageLayoutControl1);axTOCControl1.SetBuddyControl(axPageLayoutControl1);}}privatevoidopenToolStripMenuItem_Click(objectsender,EventArgse){System.Windows.Forms.OpenFileDialogopenFileDialog;openFileDialog=newOpenFileDialog();openFileDialog.Title="Open";openFileDialog.Filter="mapdocuments(*.mxd)|*.mxd";openFileDialog.ShowDialog();stringfilePath=openFileDialog.FileName;if(axMapControl2.CheckMxFile(filePath)){axMapControl2.MousePointer=esriControlsMousePointer.esriPointerHourglass;axMapControl2.LoadMxFile(filePath,0,Type.Missing);axMapControl2.MousePointer=esriControlsMousePointer.esriPointerDefault;}else{MessageBox.Show(filePath+"nousemap");}}privatevoidsaveToolStripMenuItem_Click(objectsender,EventArgse){if(MapDocument.get_IsReadOnly(MapDocument.DocumentFilename)==true){MessageBox.Show("地图文档是只读的无法保存");}stringfileSavePath=@"e:new.mxd";try{MapDocument.Save(MapDocument.UsesRelativePaths,true);MessageBox.Show("保存地图文档成功");}catch(Exceptione){MessageBox.Show("保存地图文档失败!!!"+e.ToString());}}}}错误1非静态的字段、方法或属性“ESRI.ArcGIS.Carto.IMapDocument.DocumentFilename.get”要求对象引用E:GIS作业arcgisengineGIS设计GIS设计Form1.cs8844GIS设计错误2非静态的字段、方法或属性“ESRI.ArcGIS.Carto.IMapDocument.get_IsReadOnly(string)”要求对象引用E:GIS作业arcgisengineGIS设计GIS设计Form1.cs8817GIS设计错误3非静态的字段、方法或属性“ESRI.ArcGIS.Carto.IMapDocument.UsesRelativePaths.get”要求对象引用E:GIS作业arcgisengineGIS设计GIS设计Form1.cs9535GIS设计错误4非静态的字段、方法或属性“ESRI.ArcGIS.Carto.IMapDocument.Save(bool,bool)”要求对象引用E:GIS作业arcgisengineGIS设计GIS设计Form1.cs9517GIS设计错误5不能在此范围内声明名为“e”的局部变量,因为这样会使“e”具有不同的含义,而它已在“父级或当前”范围中表示其他内容了E:GIS作业arcgisengineGIS设计GIS设计Form1.cs9830GIS设计
解决方案
解决方案二:
是从下面这一段开始出现问题上面那一段代码调试是没有问题的请问问什么这样呢privatevoidsaveToolStripMenuItem_Click(objectsender,EventArgse){if(MapDocument.get_IsReadOnly(MapDocument.DocumentFilename)==true){MessageBox.Show("地图文档是只读的无法保存");}stringfileSavePath=@"e:new.mxd";try{MapDocument.Save(MapDocument.UsesRelativePaths,true);MessageBox.Show("保存地图文档成功");}catch(Exceptione){MessageBox.Show("保存地图文档失败!!!"+e.ToString());}
解决方案三:
MapDocument如果是类的话,要改成这个类的对象
解决方案四:
看看你的ArcGIS是不是引用完全地图方法和控件是不是引用正确这几个方法是GIS封装好的你的错误5把e换成ex就行
解决方案五:
上面的问题已经解决了也可以调试但是我点击Save的时候在红色字体代码那里出现了下面的图片上的错误是什么原因呢System.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingESRI.ArcGIS.ADF;usingESRI.ArcGIS.SystemUI;usingESRI.ArcGIS.Geometry;usingESRI.ArcGIS.Display;usingESRI.ArcGIS.Controls;usingESRI.ArcGIS.esriSystem;usingESRI.ArcGIS.Carto;namespaceGIS设计{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privatevoidForm1_Load(objectsender,EventArgse){}privatevoidMainForm_Load(objectsender,EventArgse){//将主窗体放大到整个屏幕this.Size=Screen.PrimaryScreen.WorkingArea.Size;this.Location=newSystem.Drawing.Point(0,0);//将axToolbarControl和axTOCControl与axMapControl2绑定!axToolbarControl1.SetBuddyControl(axMapControl2);axTOCControl1.SetBuddyControl(axMapControl2);}privatevoidtabControl1_TabIndexChanged(objectsender,EventArgse){}privatevoidtabControl1_SelectedIndexChanged(objectsender,EventArgse){if(tabControl1.SelectedIndex==0){axToolbarControl1.SetBuddyControl(axMapControl2);axTOCControl1.SetBuddyControl(axMapControl2);}else{axToolbarControl1.SetBuddyControl(axPageLayoutControl1);axTOCControl1.SetBuddyControl(axPageLayoutControl1);}}privatevoidopenToolStripMenuItem_Click(objectsender,EventArgse){System.Windows.Forms.OpenFileDialogopenFileDialog;openFileDialog=newOpenFileDialog();openFileDialog.Title="Open";openFileDialog.Filter="mapdocuments(*.mxd)|*.mxd";openFileDialog.ShowDialog();stringfilePath=openFileDialog.FileName;if(axMapControl2.CheckMxFile(filePath)){axMapControl2.MousePointer=esriControlsMousePointer.esriPointerHourglass;axMapControl2.LoadMxFile(filePath,0,Type.Missing);axMapControl2.MousePointer=esriControlsMousePointer.esriPointerDefault;}else{MessageBox.Show(filePath+"nousemap");}}IMapDocumentmapDocument;privatevoidsaveToolStripMenuItem_Click(objectsender,EventArgse){mapDocument=newMapDocumentClass();if(mapDocument.get_IsReadOnly(mapDocument.DocumentFilename)==true){MessageBox.Show("地图文档是只读的无法保存");}try{mapDocument.Save(mapDocument.UsesRelativePaths,true);MessageBox.Show("保存地图文档成功");}catch(Exceptionex){MessageBox.Show("保存地图文档失败!!!"+ex.ToString());}}}}
解决方案六:
最后的问题楼主解决了吗?遇到同样的问题了
解决方案七:
因为少了一段代码,mapDocument还没有和文件相关联