This is related to an ArcMap add-in I coded up this past week.

I'm trying to rename a layer in ArcMap and have the legend refresh properly. The renaming part is working fine, however I cannot get the legend in the layout to update properly.

I call CurrentContents.Refresh() to refresh the name in the table of contents, which works.

If I search through the map surrounds and call .Refresh() on the legend, then do an ActiveView.PartialRefresh() on it, the legend gets all out of whack. This is why I am trying to simply trigger the same event as when the user manually changes the name of a layer.

The API documentation seems to say that MxDocument.UpdateContents() will trigger the events needed to refresh the legend. However, this does not seem to be the case. In addition to the above methods I have tried ActiveView.ContentsChanged() to no avail.

Edit: I am writing this in C# but can read VB if you feel more comfortable writing in that.

Any suggestions are welcome.



  • 1
    I recall dealing with legend resizing problems. As a workaround I stored a copy of the original height and width of the legend, then after refreshing I used ITransform2D.Scale to correct the legends mapsurround frame with a factor based on the ratio of old to new width and height. Jun 14, 2011 at 3:54
  • The workaround I've come up with is to remove and add an item from the legend programmatically. The tool I'm writing changes the height of the legend, so the 2d transform math doesn't seem feasible, and this has to be a perfect addition rather than a scale - otherwise my analysts won't use it. I'm not answering my own question here because I believe this to be a a kluge rather than an answer, despite it working precisely how I want.
    – MSavage
    Jun 14, 2011 at 13:25

2 Answers 2


I believe you have to refresh via IMapSurround. See code below.

            Dim pMxDoc As IMxDocument
            Dim pPageLayout As IPageLayout
            Dim pGC As IGraphicsContainer
            Dim pElem As IElement
            Dim pMSF As IMapSurroundFrame
            Dim pMS As IMapSurround

            Set pMxDoc = ThisDocument
            Set pPageLayout = pMxDoc.PageLayout
            Set pGC = pPageLayout

            Set pElem = pGC.Next
                Do Until pElem Is Nothing
                If TypeOf pElem Is IMapSurroundFrame Then
                    Set pMSF = pElem
                    Set pMS = pMSF.MapSurround

                End If
                Set pElem = pGC.Next

  • I stated above that I tried that and it caused the legend to get all out of whack. Specifically, the legend refreshes to show my changes, but the legend resizes within its frame and looks completely different and wrong.
    – MSavage
    Jun 13, 2011 at 22:06

I know you mention both of these methods, but I wanted to ensure you'd tried them in the correct order:

After performing your rename, first call IActiveView.ContentsChanged to signal the proper listeners and then call IActiveView.Refresh to perform the actual visual update.

  • I have indeed tried them in that order. I wish the legend didn't get all weird when I do the ILegend.Refresh() + PartialRefresh(). It all looked so perfect at first.
    – MSavage
    Jun 14, 2011 at 2:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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