Copy the PageLayoutControl focus map and overwrite the MapControl map


Purpose
This sample demonstrates how to set the PageLayoutControl's FocusMap and use the IObjectCopy object to overwrite the MapControl's map object with a copy of the PageLayoutControl's FocusMap. The map object must be copied because the MapControl and PageLayoutControl are unable to share the same ActiveView at the same time.

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. Load a map document into the PageLayoutControl.
  2. Use the left mouse button to zoom in and the right mouse button to pan both the page and the map data.
  3. Change the PageLayoutControl's FocusMap.

Additional information

The Browse dialog box allows you to search and select map documents, which are validated and loaded into the PageLayoutControl using the CheckMxFile and LoadMxFile methods. This triggers the OnPageLayoutReplaced event, which loops through the elements in the PageLayoutControl's GraphicsContainer finding MapFrame elements. The name of each MapFrame is set to the name of the map in the MapFrame using the IElementProperties interface. A combo box is populated with all of the map names to allow you to change the FocusMap. The FindElementByName method is used to find the MapFrame containing the map that is to become the FocusMap.
The PageLayoutControl's OnFocusMapChanged and OnAfterScreenDraw (when a new map document has been loaded into the PageLayoutControl) events use the IObjectCopy Copy and Overwrite methods to overwrite the MapControl's map with a copy of the PageLayoutControl's FocusMap.
Each map contained within the PageLayout, encapsulated by the PageLayoutControl, resides within a separate MapFrame, and therefore has its IMap.IsFramed property set to true. A map contained within the MapControl does not reside within a MapFrame. As such, before overwriting the MapControl's map, the IMap.IsFramed property must be set to false. (Failure to do this will lead to corrupted map documents containing the contents of the MapControl being saved).
The PageLayoutControl and MapControl OnMouseDown events use the TrackRectangle and Pan methods to zoom in and pan around either the PageLayoutControl's page or the MapControl's map. If the MapControl's display is redrawn due to a change in VisibleExtent, the OnAfterScreenDraw event is used to set the extent of the PageLayoutControl's FocusMap equal to that of the MapControl using the IDisplayTransformation interface.


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

Download the files for all languages

See Also:

PageLayoutControl class
IPageLayoutControl interface
IObjectCopy interface




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