Update MapControl Map with FocusMap


This sample demonstrates setting the PageLayoutControl's FocusMap and using the IObjecyCopy helper within the ESRI Controls Support Library to overwrite the MapControl's Map object with a copy of the PageLayoutControl's FocusMap. The Map object has to copied because the MapControl and PageLayoutControl are unable to share the same ActiveView at the same time.

The Microsoft Common Dialog Control (Comdlg32.ocx) 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 Map name's 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.

The PageLayoutControl and MapControl OnMouseDown event's use the TrackRectangle and Pan methods to zoomin 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 set the Extent of the PageLayoutControl's FocusMap equal to that of the MapControl using the IDisplayTransformation interface.

How to use:
  1. Either run the CopyFocusMap.exe or open the CopyFocusMap.vbp and run from within the project.
  2. Load a Map Document into the PageLayoutControl.
  3. Use the left hand mouse button to zoom in and the right hand mouse button to pan both Page and the Map data.
  4. Change the PageLayoutControl's FocusMap.

MapControl, PageLayoutControl

Minimum ArcGIS Version Required: 8.2

Difficulty: Beginner

Visual Basic
File Description
CopyFocusMap.frm VB form file for the CopyFocusMap project.
CopyFocusMap.frx VB Binary file.
CopyFocusMap.vbp VB Project file.

Key CoClasses: MapControl, PageLayoutControl
Key Interfaces: IDisplayTransformation, IElement, IElementProperties, IMapFrame, IObjectCopy
Key Members: ActiveView, CheckMxFile, Copy, Extent, FindElementByName, FullExtent, GraphicsContainer, LoadMxFile, MousePointer, Overwrite, Refresh, ShowScrollbars, TrackRectangle, ZoomToWholePage