我有一个由 ArcGIS 引擎 SDK 10.1 版提供支持的 .NET 程序类型,旨在按圆圈选择图层。IDE是Microsoft Visual Studio 2010。程序可以编译但运行出错。
一些代码如下所示:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using ESRI.ArcGIS.ArcMapUI;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;
namespace SelectByCircle
{
public class SelectByCircle : ESRI.ArcGIS.Desktop.AddIns.Tool
{
public SelectByCircle()
{
}
protected override void OnUpdate()
{
Enabled = ArcMap.Application != null;
}
protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg)
{
IHookHelper pHookHelper = new HookHelperClass();
pHookHelper.Hook = this.Hook;
IntPtr pHandle = new IntPtr(pHookHelper.ActiveView.ScreenDisplay.hWnd);
//axMapControl=null when debuging
AxMapControl axMapControl = System.Windows.Forms.Form.FromHandle(pHandle) as AxMapControl;
IMapControlDefault pMapControl = axMapControl.Object as IMapControlDefault;
pMapControl.Map.ClearSelection();
IGeometry pGeo;
pGeo = pMapControl.TrackCircle();
pMapControl.Map.SelectByShape(pGeo, null, false);
pMapControl.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
}
}
}
通过调试,发现程序运行时axMapControl为null。什么事?
我曾经使用 ArcGIS 引擎 WinForm 类型的程序从 this.Hook 成功获得 AxMapControl 对象。那么有什么区别呢?