自定义的工具比内置的工具有好多好处,拿放大两倍的按钮(ControlsMapZoomOutFixedCommand)来说,如果我们要单击放大三倍,那就只能自定义了,虽然原理一样。此外它的其他属性如bitmap、Name、Caption、Cursor等都是只读的(或者说是被封装了)。这也就是基于AE的应用软件都是自己写工具的主要原因吧。
ICommand和ITool接口:
ICommand应该好理解,类似于一个命令按钮,单击则执行命令。其属性也和VB里Command控件类似。常用的方法是OnClick()和OnCreate(),分别是在点击和创建的时候发生。
ITool其实是一个需要与界面交互的command。ZoomIn就是一个很好的例子。以下是原文:
Tools are similar to buttons but they also require interaction with the application's display. The Zoom In command is a good example of a tool--you click or drag a rectangle over a map before the display is redrawn to show the map contents in more detail.
ITool有个Cusor的属性代表光标的形状(mouse pointer ),其他的事件对应与VB里鼠标或键盘的响应事件例如OnMouseDown等。
ICommand和ITool应用举例:
//ITool
private void Pan_Click(object sender, EventArgs e)
{
ControlsMapPanTool pan = new ControlsMapPanToolClass();
pan.OnCreate(axMapControl1.Object);
axMapControl1.CurrentTool = (ITool)pan;
}
//ICommand
private void FullExtent_Click(object sender, EventArgs e)
{
ControlsMapFullExtentCommand fullextent = new ControlsMapFullExtentCommandClass();
fullextent.OnCreate(axMapControl1.Object);
fullextent.OnClick();
}