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. 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. 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.


Download the files for Java
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 Runtime
ArcView
ArcEditor
ArcInfo