Map as toolbar buddy


Purpose
This sample demonstrates setting a user application, supporting the IToolbarBuddy interface as the Toolbar control buddy. The buddy application is a form that implements IToolbarBuddy and contains the Map control and PageLayout control. The Toolbar control uses the buddy application to set the CurrentTool. This sample contains four commands that are defined in one application.
Items are added to the Toolbar control by passing the LoadMxFile, ZoomIn, ZoomOut, and FullExtent commands (defined in the application) to the AddItem method. Each item's Command.OnCreate method is passed to the Toolbar control as the hook. The application is accessed from the hook's buddy. Each command is written to handle the application and work with both the Map control and PageLayout control. For example, the ZoomIn command works with the Map control in map units and with the PageLayout control in page units.
To set the application as a buddy, the application must implement the IToolbarBuddy interface. The CurrentTool of both the Map control and PageLayout control is set to the IToolbarBuddy.CurrentTool property. The TabStrip control's click event determines whether the Map control or PageLayout control is the active control that the Toolbar control item commands will work with.

How to use

See How to use ArcGIS samples for help on running the sample.

  1. Run the MapAsToolbarBuddy application.
  2. Use the OpenMxFile command to load a map document into the Map control and PageLayout control.
  3. Use the ZoomIn, ZoomOut, and FullExtent commands with both the Map control and the PageLayout control.

If you installed the samples feature, you will find the files associated with this sample in <Your Developer Kit install location>\DeveloperKit10.4\Java\Samples\ArcObjects.

toolbarbean/MapAsToolbarBuddy.java Main class.
toolbarbean/commands/FullExtentCommand.java Implementation of a custom command. It shows the map in full extent.
toolbarbean/commands/OpenCommand.java Implementation of a custom command. It allows you to open map documents.
toolbarbean/commands/ZoomInCommand.java Implementation of a custom command. It allows you to zoom in on the map.
toolbarbean/commands/ZoomOutCommand.java Implementation of a custom command. It allows you to zoom out from the map.




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