public void AddScalebar(IPageLayout pageLayout, IMap map)

        if (pageLayout == null || map == null)

        IEnvelope envelope = new EnvelopeClass();
        envelope.PutCoords(0.2, 0.2, 1, 2); // Specify the location and size of the scalebar
        IUID uid = new UIDClass();
        uid.Value = "esriCarto.AlternatingScaleBar";

        // Create a Surround. Set the geometry of the MapSurroundFrame to give it a location
        // Activate it and add it to the PageLayout's graphics container
        IGraphicsContainer graphicsContainer = pageLayout as IGraphicsContainer; // Dynamic Cast
        IActiveView activeView = pageLayout as IActiveView; // Dynamic Cast
        IFrameElement frameElement = graphicsContainer.FindFrame(map);
        IMapFrame mapFrame = frameElement as IMapFrame; // Dynamic Cast
        IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid as ESRI.ArcGIS.esriSystem.UID, null); // Dynamic Cast
        IElement element = mapSurroundFrame as IElement; // Dynamic Cast
        element.Geometry = envelope;
        graphicsContainer.AddElement(element, 0);
        IMapSurround mapSurround = mapSurroundFrame.MapSurround;

        IScaleBar markerScaleBar = ((IScaleBar)(mapSurround));
        markerScaleBar.LabelPosition = esriVertPosEnum.esriBelow;

I used this code for add scale bar to my layout view.

        string fileName = @"C:\Users\damitha.a\Desktop\Student\ARC2\Web_maps\exercise 2.mxd";
        IMapDocument mapDocument = new MapDocumentClass();
        mapDocument.Open(fileName, "");
        IPageLayout pageLayout = mapDocument.PageLayout;
        IActiveView activeView = (IActiveView)pageLayout;
        IMap map = activeView.FocusMap;

        AddScalebar(pageLayout, map);


In this code I call "AddScalebar" method. it run correctly. But I didn't get any View. I'm new to GIS. Please tell me the way to get the Layout view.


In your code you get reference to the map document from a string path (fileName). Your code then creates the scale bar and adds it to the graphics container on the page layout....But... you do not save your changes! You need to save the mxd.

  • Can I export that layout to JPG – damitha Aug 25 '17 at 7:14
  • Have a look here, it's all in the help file. – Hornbydd Aug 25 '17 at 8:41

Have a try adding a refresh method to the activeView object by


  • Could you add more details on why? – BERA Aug 24 '17 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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