How to create a command or tool to work with the controls


SummaryThe ArcGIS Visual Studio integrated development environment (IDE) Integration Framework provides ArcGIS Base Command and Base Tool item templates. These can be used to create custom commands and tools to work with the ArcGIS Engine controls. This topic provides an overview of how Base Command and Base Tool items can be created and, once they are created, how they can be used with the ArcGIS Engine controls in a custom application.

Development licensing Deployment licensing
Engine Developer Kit Engine Runtime
ArcView
ArcEditor
ArcInfo

In this topic


About ArcGIS Base Command and Base Tool

The ArcGIS Visual Studio IDE Integration Framework includes item templates for the ArcGIS Base Command and Base Tool. Using these item templates allows you to create commands and tools more efficiently than directly implementing the ICommand and ITool interfaces. The following are the advantages of using the item templates:
Abstract classes cannot be instantiated and frequently contain only partial implementation code or no implementation at all. They are closely related to interfaces. However, they differ significantly from interfaces in that a class may implement any number of interfaces, but it can inherit from only one abstract class. 
A GlobeHookHelper or SceneHookHelper object can also be used. The GlobeHookHelper object is used to hold on to the hook, and the IGlobeHookHelper interface it implements can return the Camera, Globe, GlobeDisplay, and ActiveViewer regardless of the type of hook that is passed. The SceneHookHelper object is used to hold on to the hook, and the ISceneHookHelper interface it implements can return the SceneViewer, Scene, SceneGraph, and Camera regardless of the type of hook that is passed.

Creating a Base Command or Base Tool

  1. To add an ArcGIS Base Tool or Base Command to your Microsoft Visual Studio project, do one of the following:
  2. Select Base Command or Base Tool from the Add New Item dialog box. See the following screen shot:


  3. After you click Add, the ArcGIS New Item Wizard Options dialog box appears. Select the type of command or tool you want to create and click OK. The type of command or tool you choose depends on the ArcGIS Engine control or ArcGIS Desktop application you want the command or tool to work with. See the following screen shots:


A Universal Command or Universal Tool works with the ArcGIS Engine MapControl, PageLayoutControl, GlobeControl, and SceneControl, as well as the ArcGIS Desktop ArcMap, ArcGlobe, and ArcScene applications. A Blank Command or Blank Tool does not contain any component category registration code or any implementation within the OnCreate method; you need to provide this.
  1. Add custom functionality to the command or tool. For example, provide Bitmap, Caption, Category, Name, Message, and ToolTip values for the command or tool in the class constructor. In the case of a command, provide implementation in the OnClick method. In the case of a tool, provide implementation in the OnMouseDown, OnMouseMove, or OnMouseUp methods.
 
See Building a map viewing application using the ArcGIS Engine controls for more information on using the ArcGIS Base Tool to create a custom Add Date tool for the ArcGIS Engine MapControl and PageLayoutControl.

Using a Base Command or Base Tool in an application

There are several ways a custom ArcGIS Base Command or Base Tool can be used in an application once it has been fully implemented and built as discussed next. For further information, see the following:
 
Using the ArcGIS Engine ToolbarControl 
In custom ArcGIS Engine applications in which you use the ToolbarControl in conjunction with a buddy control (MapControl, PageLayoutControl, GlobeControl, or SceneControl), the command or tool can be added to the ToolbarControl in one of the following ways:
 
Once a command or tool has been added to the ToolbarControl, the ToolbarControl passes the hook to the OnCreate  method.
In this case, the hook that is passed is the actual ToolbarControl. If the command or tool uses a HookHelper, GlobeHookHelper, or SceneHookHelper object, they internally return properties from the ToolbarControl Buddy (MapControl, PageLayoutControl, GlobeControl, or SceneControl).
Using the ArcGIS Engine controls without the ToolbarControl
In custom ArcGIS Engine applications where the ToolbarControl is not required, the command or tool must work directly with the MapControl, PageLayoutControl, GlobeControl, or SceneControl. As a developer, you must programmatically perform the following tasks:
  1. Create a new instance of the command or tool.
  2. Pass the individual ArcGIS Engine control to the OnCreate method. When passing the control, use the Object property (for example, AxGlobeControl.Object when using the host wrapper) to ensure the real control is passed to the command or tool. This is done because .NET contains the real control inside a wrapper object or host.
The ArcGIS Engine controls are contained in a Controls library. For the .NET application programming interface (API), there are two primary interop assemblies provided by ESRI for the ArcGIS Engine controls. The first, ESRI.ArcGIS.AxControl, inherits from the .NET AxHost class and enables the controls to be embedded into a .NET container, such as a form. The second, ESRI.ArcGIS.Control, is a wrapper around the actual type library.
  1. In the case of a command, call the OnClick method at the appropriate time to perform the specific action. See the following code example:

[C#]
//Create a command instance.
ICommand command = new myCommandClass();
//Pass the MapControl to the OnCreate method.
command.OnCreate(axMapControl1.Object);
//Call OnClick.
command.OnClick();

[VB.NET]
'Create a command instance.
Dim command As ICommand = New myCommandClass()
'Pass the MapControl to the OnCreate method.
command.OnCreate(AxMapControl1.Object)
'Call OnClick.
command.OnClick()
  1. In the case of a tool, set the CurrentTool of the ArcGIS Engine control. The ArcGIS Engine control sends any keyboard and mouse event to the tool. See the following code example:

[C#]
//Create a tool instance.
ICommand command = new myToolClass();
//Pass the MapControl to the OnCreate method.
command.OnCreate(axMapControl1.Object);
//Set the MapControl's current tool.
axMapControl1.CurrentTool = command as ITool;

[VB.NET]
'Create a tool instance.
Dim command As ICommand = New myToolClass()
'Pass the MapControl to the OnCreate method.
command.OnCreate(AxMapControl1.Object)
'Set the MapControl's current tool.
AxMapControl1.CurrentTool = command
  1. The Enabled, Caption, and Bitmap properties of the command or tool can be read and incorporated into properties of a command button supplied by the development environment; for example, to build up the user interface of the application.
 
Using an ArcGIS Desktop application 
A custom command or tool built with the ArcGIS Engine can be added to an ArcGIS Desktop ArcMap, ArcGlobe, or ArcScene application using, for example, the Customize dialog box supplied by these applications. This is because the libraries and objects available in ArcGIS Engine are also available in ArcGIS Desktop.


See Also:

Building a map viewing application using the ArcGIS Engine controls
Controls library