I've got a .NET program type powered by ArcGIS engine SDK version 10.1 which aims to select layers by circle. The IDE is Microsoft Visual Studio 2010. The program can be compiled but runs with wrong.
Some code is showed below:
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);
}
}
}
With debuging, I found that axMapControl is null when the program is running. What the matter?
I once got AxMapControl object from the this.Hook successfully with an ArcGIS engine WinForm type program. So what are the differences?
The solution can be download from http://pan.baidu.com/s/1skfS9qP