ArcGIS Add-In插件开发无法获取ArcGIS Desktop中的AxMapcontrol对象
我在进行ArcGIS Add-In插件开发时,需要获取Desktop中的Mapcontrol对象,从而可以进一步的使用mapcontrol的事件。但是我无法获取AxMapcontrol对象,我的代码如下:
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 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对象为空,无法实例化,请问是什么原因,如何解决,谢谢。
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 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对象为空,无法实例化,请问是什么原因,如何解决,谢谢。
0 个回复