Copy the PageLayoutControl focus map and overwrite the MapControl map


PurposeThis sample demonstrates setting the PageLayoutControl's FocusMap and using the IObjectCopy object to overwrite the MapControl's map object with a copy of the PageLayoutControl's FocusMap. The map object has to be copied because the MapControl and PageLayoutControl are unable to share the same ActiveView at the same time.

The Browse dialog box allows users 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 ComboBox is populated with all of the map names to allow users 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 have their 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 saved containing the contents of the MapControl).

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.

Development licensing Deployment licensing
Engine Developer Kit Engine Runtime
ArcView
ArcEditor
ArcInfo

How to use

See Using the samples for help on compiling, setting up the debugger, and running the sample (either an exe or dll).

  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.

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