Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

For printing we have a PageLayoutControl where the user can select the map extent, he wants to print. I like the map to fill only a square in the middle of the page so that the title, the ScaleBar and some additional texts appear on top and underneath the map. By now the map fills the hole page. How can I resize the map?

I tried setting the envelopes x and y values, but with no success:

public void SizeMap(IPageLayout pageLayout, IActiveView activeView)
{
  IMap map = activeView.FocusMap;
  IGraphicsContainer graphicsContainer = pageLayout as IGraphicsContainer;
  IFrameElement frameElement = graphicsContainer.FindFrame(map);
  IMapFrame mapFrame = (IMapFrame)frameElement;

  IElement mainMap_Element = mapFrame as IElement;
  IGeometry geometry = mainMap_Element.Geometry;
  IEnvelope mainMap_Envelope = geometry.Envelope;

  mainMap_Envelope.YMin = 5; // only example values
  mainMap_Envelope.YMax = 12;

  activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}

Is this the right approach? Thanks in advance.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

After some research I found the following solution:

IGraphicsContainer pGraphicsContainer = _pageLayoutControl.GraphicsContainer;
pGraphicsContainer.Reset();
IElement pElement = pGraphicsContainer.Next();
while (pElement != null)
{
  if (pElement is IMapFrame)
  {
    IMapFrame pMapFrame = pElement as IMapFrame;
    IEnvelope pEnvelope = new EnvelopeClass();
    pEnvelope.PutCoords(0.5, 0.5, 11.5, 11.5);
    pElement.Geometry = pEnvelope;
    _pageLayoutControl.Refresh();
  }
  pElement = pGraphicsContainer.Next();
}
share|improve this answer
add comment

Your Answer

 
discard

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.