C# ArcGIS桌面加载项程序无法获取AxMapControl对象
我有一个由ArcGIS engine SDK版本10.1支持的.NET程序类型,其目标是按圆圈选择层。IDE是Microsoft Visual Studio 2010。该程序可以编译,但运行时出错 一些代码如下所示:C# ArcGIS桌面加载项程序无法获取AxMapControl对象,c#,arcgis,visual-studio-addins,arcobjects,esri-arc-engine,C#,Arcgis,Visual Studio Addins,Arcobjects,Esri Arc Engine,我有一个由ArcGIS engine 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; u
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对象。那么有什么区别呢
该解决方案可从以下网站下载: