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
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
How to use:
Either run the CopyFocusMap.exe or open the CopyFocusMap.vbp and run from within the project.
Load a Map Document into the PageLayoutControl.
Use the left hand mouse button to zoom in and the right hand mouse button to pan both Page
and the Map data.