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,

                    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);

Do you know why ?

Thanks and regards,


  • The above error only happen when the pageControl.ActiveView.FocusMap (MapFrame) is being selected
    – taibc
    Nov 6 '12 at 9:49
  • Are there anyone know how to fix it ?
    – taibc
    Nov 8 '12 at 3:48

Your Answer

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

Browse other questions tagged or ask your own question.