Building a MapViewer application using the ArcGIS Engine controls


Purpose
In this sample, the MapControl, PageLayoutControl, TOCControl, and ToolbarControl are used in conjunction with other ArcObjects and the control commands to create a Map Viewer application. This sample accompanies the Building a map viewing application using the ArcGIS Engine controls walkthrough and demonstrates the following:
  • Loading preauthored map documents into the PageLayoutControl and MapControl using the CheckMxFile and LoadMxFile methods.
  • Setting the ToolbarControl and TOCControl buddy control to be the PageLayoutControl using the SetBuddyControl method.
  • Resizing the MapControl and PageLayoutControl when the container form or dialog box is resized.
  • Adding navigation and inquiry commands to the ToolbarControl using the AddItem method.
  • Creating a pop-up menu from the commands that work with the PageLayoutControl and displays as a right-click context menu.
  • Creating a palette of tools from the commands and adding it to the ToolbarControl.
  • Managing the way map and layer labels are edited in the TOCControl using the LabelEdit property and the ITOCControlEvents.OnEndLabelEdit event.
  • Using the MapControl as an overview window by using the DrawShape method to highlight the current extent of data in the PageLayoutControl.
  • Creating a custom Add Date command that works with the PageLayoutControl, ToolbarControl, and MapControl.
  • Customizing the ToolbarControl with the Customize property and displaying the CustomizeDialog to the end user at runtime.
  • Persisting the ToolbarControl items using the SaveItems and LoadItems methods.
  • Printing the contents of the PageLayoutControl using the PrintPageLayout method.

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. Open the .NET solution file and build the projects.
  2. Run the controls application.
  3. Use the Open Document command on the ToolbarControl to browse to a preauthored map document to load into the PageLayoutControl.
  4. Use the commands and tools on the ToolbarControl to navigate around the map document. Right-click the PageLayoutControl to display the pop-up menu. Use the palette on the ToolbarControl to draw graphic elements on the PageLayoutControl.
  5. Use the custom Add Date tool to add an element to the PageLayoutControl containing the current date.
  6. Click a map or layer label in the TOCControl, then click it again to edit the label.
  7. Customize the ToolbarControl by adding new commands, menus, or palettes from the CustomizeDialog. To alter the appearance of an existing item on the ToolbarControl, right-click the item to display the context menu. Stop running the application, then restart the application to see that the customizations you made were persisted.
  8. Print the contents of the PageLayoutControl by selecting Print from the File menu.

Controls/MapViewer.cs The form file.
Controls/AssemblyInfo.cs The assembly information.
Commands/AddDateTool.cs The class file.
Commands/AssemblyInfo.cs The assembly information.
Download the C# files
Controls/MapViewer.vb The form file.
Controls/AssemblyInfo.vb The assembly information.
Commands/AddDateTool.vb The class file.
Commands/AssemblyInfo.vb The assembly information.
Download the VB.NET files

Download the files for all languages

See Also:

Walkthrough: Building a map viewing application using the ArcGIS Engine controls




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