当前位置:编程学习 > C#/ASP.NET >>

非静态的字段、方法或属性“ESRI.ArcGIS.Carto.IMapDocument.DocumentFilename.get”要求对象引用

请出现这种错误是为什么呢 该如何改正呢


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Carto;

namespace GIS设计
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        private void MainForm_Load(object sender, EventArgs e)
        {
            // 将主窗体放大到整个屏幕
            this.Size = Screen.PrimaryScreen.WorkingArea.Size;
            this.Location = new System.Drawing.Point(0, 0);

            // 将axToolbarControl和axTOCControl与axMapControl2绑定!
            axToolbarControl1.SetBuddyControl(axMapControl2);

            axTOCControl1.SetBuddyControl(axMapControl2);

        }

        private void tabControl1_TabIndexChanged(object sender, EventArgs e)
        {

        }

        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (tabControl1.SelectedIndex == 0)
            {
                axToolbarControl1.SetBuddyControl(axMapControl2);

                axTOCControl1.SetBuddyControl(axMapControl2);

            }
            else
            {
                axToolbarControl1.SetBuddyControl(axPageLayoutControl1);

                axTOCControl1.SetBuddyControl(axPageLayoutControl1);

            }
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.OpenFileDialog openFileDialog;
            openFileDialog = new OpenFileDialog();
            openFileDialog.Title = "Open";
            openFileDialog.Filter = "map documents(*.mxd)|*.mxd";
            openFileDialog.ShowDialog();
            string filePath = openFileDialog.FileName;
            if (axMapControl2.CheckMxFile(filePath))
            {
                axMapControl2.MousePointer = esriControlsMousePointer.esriPointerHourglass;
                axMapControl2.LoadMxFile(filePath, 0, Type.Missing);
                axMapControl2.MousePointer = esriControlsMousePointer.esriPointerDefault;
            }
            else
            {
                MessageBox.Show(filePath + "no use map");
            }
        }
     
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MapDocument.get_IsReadOnly(MapDocument.DocumentFilename) == true)
            {
                MessageBox.Show("地图文档是只读的无法保存");
            }
            string fileSavePath=@"e:\new.mxd";
            try
            {
                MapDocument .Save(MapDocument .UsesRelativePaths,true );
                MessageBox.Show ("保存地图文档成功");
            }
            catch (Exception e)
            {
                MessageBox .Show ("保存地图文档失败!!!"+e.ToString());
            }
        }



    }

    }


错误    1    非静态的字段、方法或属性“ESRI.ArcGIS.Carto.IMapDocument.DocumentFilename.get”要求对象引用    E:\GIS\作业\arcgis engine\GIS设计\GIS设计\Form1.cs    88    44    GIS设计
错误    2    非静态的字段、方法或属性“ESRI.ArcGIS.Carto.IMapDocument.get_IsReadOnly(string)”要求对象引用    E:\GIS\作业\arcgis engine\GIS设计\GIS设计\Form1.cs    88    17    GIS设计
错误    3    非静态的字段、方法或属性“ESRI.ArcGIS.Carto.IMapDocument.UsesRelativePaths.get”要求对象引用    E:\GIS\作业\arcgis engine\GIS设计\GIS设计\Form1.cs    95    35    GIS设计
错误    4    非静态的字段、方法或属性“ESRI.ArcGIS.Carto.IMapDocument.Save(bool, bool)”要求对象引用    E:\GIS\作业\arcgis engine\GIS设计\GIS设计\Form1.cs    95    17    GIS设计
错误    5    不能在此范围内声明名为“e”的局部变量,因为这样会使“e”具有不同的含义,而它已在“父级或当前”范围中表示其他内容了    E:\GIS\作业\arcgis engine\GIS设计\GIS设计\Form1.cs    98    30    GIS设计
--------------------编程问答-------------------- 是从下面这一段开始出现问题  上面那一段代码调试是没有问题的
请问问什么这样呢
 private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MapDocument.get_IsReadOnly(MapDocument.DocumentFilename) == true)
            {
                MessageBox.Show("地图文档是只读的无法保存");
            }
            string fileSavePath=@"e:\new.mxd";
            try
            {
                MapDocument .Save(MapDocument .UsesRelativePaths,true );
                MessageBox.Show ("保存地图文档成功");
            }
            catch (Exception e)
            {
                MessageBox .Show ("保存地图文档失败!!!"+e.ToString());
            }
--------------------编程问答-------------------- MapDocument如果是类的话,要改成这个类的对象 --------------------编程问答-------------------- 看看 你的ArcGIS 是不是引用完全 地图方法和控件是不是引用正确 这几个方法是GIS封装好的  你的错误5把e换成ex就行 --------------------编程问答-------------------- 上面的问题已经解决了  也可以调试  但是我点击Save的时候在红色字体代码那里出现了下面的图片上的错误  是什么原因呢

System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Carto;

namespace GIS设计
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        private void MainForm_Load(object sender, EventArgs e)
        {
            // 将主窗体放大到整个屏幕
            this.Size = Screen.PrimaryScreen.WorkingArea.Size;
            this.Location = new System.Drawing.Point(0, 0);

            // 将axToolbarControl和axTOCControl与axMapControl2绑定!
            axToolbarControl1.SetBuddyControl(axMapControl2);

            axTOCControl1.SetBuddyControl(axMapControl2);

        }

        private void tabControl1_TabIndexChanged(object sender, EventArgs e)
        {

        }

        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (tabControl1.SelectedIndex == 0)
            {
                axToolbarControl1.SetBuddyControl(axMapControl2);

                axTOCControl1.SetBuddyControl(axMapControl2);

            }
            else
            {
                axToolbarControl1.SetBuddyControl(axPageLayoutControl1);

                axTOCControl1.SetBuddyControl(axPageLayoutControl1);

            }
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.OpenFileDialog openFileDialog;
            openFileDialog = new OpenFileDialog();
            openFileDialog.Title = "Open";
            openFileDialog.Filter = "map documents(*.mxd)|*.mxd";
            openFileDialog.ShowDialog();
            string filePath = openFileDialog.FileName;
            if (axMapControl2.CheckMxFile(filePath))
            {
                axMapControl2.MousePointer = esriControlsMousePointer.esriPointerHourglass;
                axMapControl2.LoadMxFile(filePath, 0, Type.Missing);
                axMapControl2.MousePointer = esriControlsMousePointer.esriPointerDefault;
            }
            else
            {
                MessageBox.Show(filePath + "no use map");
            }
        }
        IMapDocument mapDocument;
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            mapDocument = new MapDocumentClass();
            if (mapDocument.get_IsReadOnly(mapDocument.DocumentFilename) == true)            {
                MessageBox.Show("地图文档是只读的无法保存");
            }
            
            try
            {
                mapDocument .Save(mapDocument .UsesRelativePaths,true );
                MessageBox.Show ("保存地图文档成功");
            }
            catch (Exception ex)
            {
                MessageBox .Show ("保存地图文档失败!!!"+ex.ToString());
            }
        }
    }

    }
--------------------编程问答-------------------- 最后的问题楼主解决了吗?遇到同样的问题了
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,