Creating a new map frame: Error HRESULT E_FAIL has been returned from a call to a COM

451
3
11-05-2012 11:57 PM
TaiBui
by
Occasional Contributor II
I am trying to create a new map frame in the PageLayout Control. But I got the error: Error HRESULT E_FAIL has been returned from a call to a COM component at the method AddElement.

Please see below codes:

                  
 IEnvelope envelope = new EnvelopeClass();
                    envelope.PutCoords(Upper_LeftX, Upper_LeftY - _Height, Upper_LeftX + _Width,
                        Upper_LeftY);

                    IMap map = new MapClass();

                    IMapFrame mapFrame = new MapFrameClass();
                    mapFrame.Map = map;
                    IElement mapElement = mapFrame as IElement;
                    mapElement.Geometry = envelope;

                    pageControl.ActiveView.GraphicsContainer.AddElement(mapElement  , 0); // throw error
                    pageControl.ActiveView.FocusMap = mapFrame.Map;
                    pageControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);


The above error only happen if the pageControl.ActiveView.FocusMap (MapFrame) is being selected.

Do you know how to fix it ?

Thanks and regards,

Tai
0 Kudos
3 Replies
TaiBui
by
Occasional Contributor II
Are there anyone can help ?
0 Kudos
EricPfirman
New Contributor III
Did you ever figure this out?
0 Kudos
TaiBui
by
Occasional Contributor II
Did you ever figure this out?


Hi,

I think it is because of there are many frames, so I deleted unecessary frames and successful

 IGraphicsContainer grpContainer = pageLayoutTo2_3.ActiveView.GraphicsContainer;
                    grpContainer.Reset();
                    IElement pElement = grpContainer.Next();
                    int iFrame = 0;
                    while (pElement != null)
                    {
                        if (pElement is IMapFrame)
                        {
                            IMapFrame frame = new MapFrameClass();
                            frame = (IMapFrame)pElement;
                            frame.Border = null;
                            iFrame++;
                            //break;
                        }
                        else if ((pElement is IMapFrame) && (iFrame > 0))
                        {
                            grpContainer.DeleteElement(pElement);

                        }
                        pElement = grpContainer.Next();
                    }
                    pageLayoutTo2_3.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
0 Kudos