基于插件技术的GIS应用框架(C# + ArcEngine9.3)(十)
---------------------------ITool的上下文菜单
大家也许没有发现,在直接将esriControls中的工具集成到自己的框架里的时候,OnContextMenu事件却无法得到处理,造成了工具没有上下文菜单,其实这也不能怪ESRI,因为当你讲MapControl或PageLayoutControl的CurrentTool设置为某个具体的esriControls中的工具,如:ControlsMapPanTool时,MapControl是不会为你调用OnContextMenu方法的,这个时候如果用户同样想拥有工具的上下文菜单时,怎么办呢?在本文论述的框架中作了如下的处理,当然可能的方法有很多种,在这里只是提供了一个参考。
下面以地图平移工具为例,来说明这个问题。
public class Pan : IAxTool, esriSystemUI.ICommand, esriSystemUI.ITool
{
private IAxApplication _App;
private esriSystemUI.ITool _tool = null;
private esriSystemUI.ICommand _cmd = null;
private System.IntPtr _Handle;
private System.Drawing.Icon _Icon;
public Pan()
{
System.Resources.ResourceManager manager = new System.Resources.ResourceManager("AxeMap.MapView.icon", System.Reflection.Assembly.GetExecutingAssembly());
object target = manager.GetObject("Pan");
_Icon = (System.Drawing.Icon)target;
_Handle = _Icon.Handle;
}
#region IAxTool 成员
public int Bitmap
{
get { return _Handle.ToInt32(); }
}
public string Caption
{
get { return "平移"; }
}
public string Category
{
get { return "地图"; }
}
public bool Checked
{
get { return false; }
}
public int Cursor
{
get
{
if (_tool != null)
{
return _tool.Cursor;
}
else
{
return (int)esriControls.esriControlsMousePointer.esriPointerPan;
}
}
}
public bool Deactivate()
{
return true;
}
public bool Enabled
{
get { return _App.FocusMap != null; }
}
public int HelpContextID
{
get { return 0; }
}