Legend Position

1037
1
07-13-2013 01:01 PM
JamesMitchell
New Contributor II
Hello,

I am hoping for some help/advice.

I am trying to get the ymax for a legend using c# but i the value returned is incorrect. The value for the width is correct though.

Please can someone explain why this does not return the correct value for ymax and how i can obtain this value?

Many thanks.


                    IGraphicsContainer graphicsContainer = mapDocument.PageLayout as IGraphicsContainer;

                    graphicsContainer.Reset();
                    IElement element = graphicsContainer.Next();

                    while (element != null)
                    {

                        if (element is IMapSurroundFrame)
                        {
                            IMapSurround mapSurround = ((IMapSurroundFrame)element).MapSurround;
                            if (mapSurround is ILegend)
                            {

                                 IEnvelope newEnvelope = new Envelope() as IEnvelope;

                                 mapSurround.QueryBounds(mapDocument.ActiveView.ScreenDisplay, element.Geometry.Envelope, newEnvelope);

                                 MessageBox.Show(newEnvelope.Envelope.YMax.ToString());
                                 MessageBox.Show(newEnvelope.Envelope.Width.ToString());
0 Kudos
1 Reply
JamesMitchell
New Contributor II
Hello,

I have managed to get the ymax by using (element.Geometry.Envelope.YMax)

However when the legend is updated and i try and get the new ymax it still returns the original ymax.

I have tried using:
legend.Refresh();
mapSurround.Refresh();
mapDocument.ActiveView.Refresh();
mapDocument.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

If i save the mxd and reopen it i can then get the new ymax.

Does anyone know how to get the ymax from a legend after it has been updated?

Thank you
0 Kudos