Move legend to specific position in Layout View

519
4
04-18-2011 10:18 AM
JamesCrandall
MVP Frequent Contributor
ArcMap 9.3.1

I have written some automation processing for Layout creation and cannot seem to get the legend that is added programmatically to a specific position in the Layout View.  As seen in the attached image, it is added and is the correct size, but I need to place it as specified.



Here's the currnt "putcoord" parameters for the lengend:

pEnv.PutCoords(0.4, 1.3, 1.75, 2.75)

Also, the page size is 8.5x11 but in Landscape orientation.

If you need to see the rest of the code that I am using to process this stuff, I can add more detailed snips.

Thanks in advance!

james
0 Kudos
4 Replies
maxsteinbrenner
New Contributor II
so the legend never moves no matter what the putcoords are?

my code for a creating/placing a legend (using putcoords to place it) is pretty long but i can post it up if it will help.
0 Kudos
JamesCrandall
MVP Frequent Contributor
so the legend never moves no matter what the putcoords are?

my code for a creating/placing a legend (using putcoords to place it) is pretty long but i can post it up if it will help.



I think that is correct.  For example, if I replace the PutCoords line with this one, it simply resizes the legend (making it larger) and appears to keep the same position:

pEnv.PutCoords(1, 1, 4, 4)



Here is the full Sub that I am using to add the Legend:


Public Sub AddMapSurrounds()
        Dim pMxDoc As IMxDocument
        Dim pActiveView As IActiveView
        Dim pEnv As IEnvelope
        Dim pId As New UID
        Dim pMapSurround As IMapSurround

        pMxDoc = m_pApp.Document
        pActiveView = pMxDoc.PageLayout
        pEnv = New Envelope
        pEnv.PutCoords(0.4, 1.3, 1.75, 2.75)
       
        pId.Value = "esricore.Legend"
        pMapSurround = CreateSurround(pId, pEnv, "Index Reporting", pMxDoc.FocusMap, pMxDoc.PageLayout)
        pMapSurround.Refresh()

        pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, Nothing, Nothing)

End Sub
0 Kudos
JeffreyHamblin
New Contributor III
Looks to me like it needs to be something more like:

pEnv.PutCoords(9.0, 0.75, 10.35, 2.2)


The parameters position the corners referencing zero as the lower left page corner:

LowerLeftX, LowerLeftY, UpperRightX, UpperRightY

So the size of the envelope is determined by the difference between the values.


-Jeff H
0 Kudos
JamesCrandall
MVP Frequent Contributor
Looks to me like it needs to be something more like:

pEnv.PutCoords(9.0, 0.75, 10.35, 2.2)


The parameters position the corners referencing zero as the lower left page corner:

LowerLeftX, LowerLeftY, UpperRightX, UpperRightY

So the size of the envelope is determined by the difference between the values.

-Jeff H


That looks pretty good to me, Jeff.  Thanks for the help!

james
0 Kudos