Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In my print preview dialog I have a PageLayoutControl loading the same map as the main view's MapControl. I want the map in the PageLayoutControl to center at the same position as the MapControl. Using Extent is not a solution because the PageLayoutControl has a fixed ratio (square). (I tried using the same extent, but it didn't work at all.)

I tried the following, but CenterAt() didn't do the trick.

  IEnvelope extent = _mapControl.Extent;
  double lXMin, lXMax, lYMin, lYMax;
  lXMin = extent.XMin;
  lXMax = extent.XMax;
  lYMin = extent.YMin;
  lYMax = extent.YMax;

  IPoint centerPoint = new PointClass();
  centerPoint.SpatialReference = _mapControl.SpatialReference;
  centerPoint.X = lXMin + ((lXMax - lXMin) / 2);
  centerPoint.Y = lYMin + ((lYMax - lYMin) / 2);

Neither did Extent.CenterAt() help:


I don't have MapServer, so I can't use ICenterAndScale. I didn't find a MapDescription in the PageLayoutControl at all.

Any hints?

share|improve this question
up vote 3 down vote accepted

Try the following when you switch from the MapControl to the PageLayoutControl or when you show the PageLayout. The application I tested on was using a tab control so...

private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
    if (e.TabPageIndex == 1)
        IPageLayout pageLayout = (IPageLayout)axPageLayoutControl1.ActiveView;
        syncExtent(pageLayout, (IEnvelope)axMapControl1.ActiveView.Extent);

private void syncExtent(IPageLayout pageLayout, IEnvelope env)
    IGraphicsContainer graphicsContainer = (IGraphicsContainer)pageLayout;
    IElement element = graphicsContainer.Next();
    while (element != null)
        if (element is IMapFrame)
            IMapFrame mapFrame = (IMapFrame)element;
            IActiveView tmpActiveView = (IActiveView)mapFrame.Map;
            tmpActiveView.Extent = env;
        element = graphicsContainer.Next();
share|improve this answer

If you need close integration between the MapControl and PagelayoutControl you should look at the sample in Concept & Samples section in the documentation, See How to synchronize the MapControl and PageLayoutControl

share|improve this answer
Thanks. I tried this but I had problems on resetting the MapControl.Map back to it's initial state, when the user changed something (extent, scale...) in the print preview's PageLayoutControl. – gumo Sep 23 '11 at 10:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.