下面是添加图框的基本方法和步骤:
///<summary> ///添加地图框架 ///</summary> ///<paramname="sender"></param> ///<paramname="e"></param> private void wndBtnAddMapFrame_ItemClick(objectsender, ItemClickEventArgse) { IEnvelope envelop= new EnvelopeClass(); envelop.XMin= 2; envelop.YMin= 2; envelop.XMax= 5; envelop.YMin= 5; IMapFrame p_MapFrame= newMapFrameClass(); p_MapFrame.Map=new MapClass(); IElement ele= p_MapFrame as IElement; wndPageLayout.AddElement((IElement)p_MapFrame,envelop,null, null, 0); IGraphicsContainerSelect graphSelect = wndPageLayout.PageLayoutas IGraphicsContainerSelect; graphSelect.SelectElement(ele); wndPageLayout.Refresh(esriViewDrawPhase.esriViewGraphicSelection,null,null); }本例中自己定义了一个Envelope,在实际开发中,这个图框的大小可以通过绘制矩形框获取,或者根据现有页面自动生成,如下:
private void wndBtnAddMapFrame_ItemClick(object sender, ItemClickEventArgs e) { double width, height; wndPageLayout.Page.QuerySize(out width, out height); IEnvelope pEnvelop = new EnvelopeClass(); pEnvelop.PutCoords(0, 0, width, height); pEnvelop.Expand(0.5, 0.3, true); IMapFrame p_MapFrame = new MapFrameClass(); IMap pMap = new MapClass(); p_MapFrame.Map = pMap; p_MapFrame.Map.Name = "New Data Frame"; IElement ele = p_MapFrame as IElement; wndPageLayout.AddElement((IElement)p_MapFrame, pEnvelop, null, null, 0); IGraphicsContainerSelect graphSelect = wndPageLayout.PageLayout as IGraphicsContainerSelect; graphSelect.SelectElement(ele); wndPageLayout.Refresh(esriViewDrawPhase.esriViewGraphics, null, null); }
当然,与这种处理方法效果等价的最简单的办法是直接调用添加MapFrame的ICommand命令,如下:
ICommand pCmd = new ControlsPageNewMapCommand(); pCmd.OnCreate(wndPageLayout.Object); pCmd.OnClick();