首页 > 代码库 > C#+ArcEngine打印横向和纵向调整

C#+ArcEngine打印横向和纵向调整

在用C#开发ArcEngine程序实现Pagelaylout打印功能的时候,在实现横向打印的时候,总会出现如下图的情况

  技术分享

通过修改axPageLayoutControl1.Page.Orientation = 1;属性发现也不作用;需要通过修改IMapFrame进行修改能够实现横向和纵向的合理变化;

 

横向显示代码如下

 

    IMap pMap;

    IGraphicsContainer pGraphicsContainer;

    IMapFrame pMapFrame;

    pMap = axPageLayoutControl1.ActiveView.FocusMap;

    pGraphicsContainer = (IGraphicsContainer)axPageLayoutControl1.PageLayout;

    pMapFrame = (IMapFrame)pGraphicsContainer.FindFrame(pMap);

    ISymbolBorder pSymborder = new SymbolBorderClass();

    pSymborder.CornerRounding = 0;

    IBorder pBorder = pSymborder;

    pMapFrame.Border = pBorder;

    pMapFrame.ExtentType = esriExtentTypeEnum.esriExtentBounds;

    IElement pElement = (IElement)pMapFrame;

    IEnvelope pEnvelop =  new EnvelopeClass();

    pEnvelop.PutCoords(0.5, 0.5, 29.2, 20.5);   //这里设置mapframe的大小

    IGeometry pGeometry = pEnvelop;

    pElement.Geometry = pGeometry;

    IPage pPage = axPageLayoutControl1.Page;

    pPage.Orientation = 1;

    pPage.PutCustomSize(29.7, 21.0);  //这里设置page的大小

    axPageLayoutControl1.ActiveView.Refresh();

 

效果如下图

 

 技术分享 

 

    IMap pMap;

    IGraphicsContainer pGraphicsContainer;

    IMapFrame pMapFrame;

    pMap = axPageLayoutControl1.ActiveView.FocusMap;

    pGraphicsContainer = (IGraphicsContainer)axPageLayoutControl1.PageLayout;

    pMapFrame = (IMapFrame)pGraphicsContainer.FindFrame(pMap);

    ISymbolBorder pSymborder = new SymbolBorderClass();

    pSymborder.CornerRounding = 0;

    IBorder pBorder = pSymborder;

    pMapFrame.Border = pBorder;

    pMapFrame.ExtentType = esriExtentTypeEnum.esriExtentBounds;

    IElement pElement = (IElement)pMapFrame;

    IEnvelope pEnvelop =  new EnvelopeClass();

    pEnvelop.PutCoords(0.5, 0.5, 20.5,29.2);   //这里设置mapframe的大小

    IGeometry pGeometry = pEnvelop;

    pElement.Geometry = pGeometry;

    IPage pPage = axPageLayoutControl1.Page;

    pPage.Orientation = 2;

    pPage.PutCustomSize(21.0, 29.7);  //这里设置page的大小

    axPageLayoutControl1.ActiveView.Refresh();

效果如下图

 技术分享

 

本实例使用A4纸张的尺寸进行测试,具体的应用还要根据实际的情况进行设置。

 

 

 

 

纵向显示代码如下

 

C#+ArcEngine打印横向和纵向调整