2 casen xu casen_xu 于 2013.12.24 21:09 提问

ArcGIS Engine10.0 显示属性表的时候不成功,代码最后两行有问题,已标注,求解。

源码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;

using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geodatabase;

namespace GIS_Design
{
public partial class Form1 : Form
{
public Form1()
{
ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);

        InitializeComponent();
    }



    private void axMapControl1_OnMapReplaced(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMapReplacedEvent e)
    {
        if (axMapControl1.LayerCount > 0)
        {
            axMapControl2.Map = new MapClass();
            for (int i = 0; i <= axMapControl1.Map.LayerCount - 1; i++)
            {
                axMapControl2.AddLayer(axMapControl1.get_Layer(i));
            }
            axMapControl2.Extent = axMapControl1.Extent;
            axMapControl2.Refresh();
        }
    }

    private void axMapControl1_OnExtentUpdated(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnExtentUpdatedEvent e)
    {
        // 得到新范围
        IEnvelope pEnvelope = (IEnvelope)e.newEnvelope;
        IGraphicsContainer pGraphicsContainer = axMapControl2.Map as IGraphicsContainer;
        IActiveView pActiveView = pGraphicsContainer as IActiveView;
        //在绘制前,清除axMapControl2中的任何图形元素
        pGraphicsContainer.DeleteAllElements();

        IRectangleElement pRectangleEle = new RectangleElementClass();
        IElement pElement = pRectangleEle as IElement;
        pElement.Geometry = pEnvelope;
        //设置鹰眼图中的红线框
        IRgbColor pColor = new RgbColorClass();
        pColor.Red = 255;
        pColor.Green = 0;
        pColor.Blue = 0;
        pColor.Transparency = 255;
        //产生一个线符号对象
        ILineSymbol pOutline = new SimpleLineSymbolClass();
        pOutline.Width = 3;
        pOutline.Color = pColor;
        //设置颜色属性
        pColor = new RgbColorClass();
        pColor.Red = 255;
        pColor.Green = 0;
        pColor.Blue = 0;
        pColor.Transparency = 0;
        //设置填充符号的属性
        IFillSymbol pFillSymbol = new SimpleFillSymbolClass();

        pFillSymbol.Color = pColor;
        pFillSymbol.Outline = pOutline;
        IFillShapeElement pFillShapeEle = pElement as IFillShapeElement;
        pFillShapeEle.Symbol = pFillSymbol;
        pGraphicsContainer.AddElement((IElement)pFillShapeEle, 0);
        pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
    }       
    private void axMapControl2_OnMouseMove(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e)
    {

        if (e.button == 1)
        {
            IPoint pPoint = new ESRI.ArcGIS.Geometry.Point();
        pPoint.PutCoords(e.mapX, e.mapY);
        axMapControl1.CenterAt(pPoint);
        axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
        }
    }

    private void axMapControl2_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
    {

        if (axMapControl2.Map.LayerCount > 0)
        {
            if (e.button == 1)
            {
                IPoint pPoint = new ESRI.ArcGIS.Geometry.Point();
                pPoint.PutCoords(e.mapX, e.mapY);
                axMapControl1.CenterAt(pPoint);
                axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            }
            else if (e.button == 2)
            {
                IEnvelope pEnv = axMapControl2.TrackRectangle();
                axMapControl1.Extent = pEnv;
                axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            }
        }
    }

    private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
    {

    }
    ILayer layer = new FeatureLayerClass();
    private void axTOCControl1_OnMouseDown_1(object sender, ESRI.ArcGIS.Controls.ITOCControlEvents_OnMouseDownEvent e)
    {
        this.axTOCControl1.ContextMenuStrip = null;
        IBasicMap map = new MapClass();

        System.Object other = null;
        System.Object index = null;
        ESRI.ArcGIS.Controls.esriTOCControlItem item = ESRI.ArcGIS.Controls.esriTOCControlItem.esriTOCControlItemNone;
        this.axTOCControl1.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index);
        if (item == ESRI.ArcGIS.Controls.esriTOCControlItem.esriTOCControlItemLayer && e.button == 2)
        {
            System.Drawing.Point pt = new System.Drawing.Point();
            pt.X = e.x;
            pt.Y = e.y;
            pt = this.axTOCControl1.PointToScreen(pt);
            this.contextMenuStrip4.Show(pt);
        }
    }
    private void OpenAttribute_Click(object sender, EventArgs e)
    {
         **Form Attribute   = new Attribute(layer);
        Form.Show();**  
    }        
}

}
错误 CS0144: 无法创建抽象类或接口“System.Attribute”的实例
错误 CS0120: 非静态的字段、方法或属性“System.Windows.Forms.Control.Show()”要求对象引用

1个回答

selfer520
selfer520   2014.05.16 15:52
已采纳
**Form Attribute   = new Attribute(layer);
    Form.Show();** 

应该是
**Attribute Form = new Attribute(layer);
Form.Show();

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!