Share a command pool between ToolbarControls


Purpose
This sample demonstrates what happens when multiple ToolbarControls share the same CommandPool and use the ToolbarControl in conjunction with the MapControl and control commands.

How to use

See How to use ArcGIS samples for help on compiling, setting up the debugger, and running the sample. If the sample has associated data, you will find that the sample's zip file includes a "data" folder alongside the language folders. However, you will need to update the sample to point to the location of the data once you have extracted all the files.

  1. Browse to a map document to load into the MapControl.
  2. Click the ZoomIn, ZoomOut, or Pan tool (only one tool is depressed).
  3. Share the same CommandPool between both ToolbarControls (the UsageCount changes).
  4. Click the ZoomIn, ZoomOut, or Pan tool (the same tool on both ToolbarControls are depressed).

Additional information

The AddItem method is used within the Form_Load event to add four new items to ToolbarControl1 and ToolbarControl2. Three of the items that are added to ToolbarControl1 are also added to ToolbarControl2. By default, each ToolbarControl has its own CommandPool to which these items' commands are added. One instance of each command in the CommandPool of ToolbarControl1 is used by ToolbarControl1; consequently, the ICommandPool.UsageCount of each command is one. This is the same for ToolbarControl2.
By selecting the check box, ToolbarControl1 and ToolbarControl2 share the CommandPool of ToolbarControl1. If any command used by ToolbarControl2 is in the CommandPool, the ICommand.UsageCount of that command increments by one. If any command used by ToolbarControl2 is not in the CommandPool, the command is added to the CommandPool with an ICommandPool.UsageCount of one.


AssemblyInfo.cs Assembly information.
ShareCommandPool.cs Form file.
Download the C# files
AssemblyInfo.vb Assembly information.
ShareCommandPool.vb Form file.
Download the VB.NET files

Download the files for all languages

See Also:

ToolbarControl Class
IToolbarControl Interface
ICommandPool Interface




Development licensing Deployment licensing
Engine Developer Kit Engine
ArcGIS for Desktop Basic
ArcGIS for Desktop Standard
ArcGIS for Desktop Advanced