set page layout for report viewer in visual studio 2010

偶尔善良 提交于 2019-12-03 05:09:46

问题


I again have a little problem. I have used ReportViewer in my Windows Form Application in visual studio 2010. The width of my report id about 7 inches. When i view the report in print layout, the report is cut across the page,i.e, only half of the content is on the page and rest is out of right margin and page boundary. I then have to click page setup in the report viewer top menu to change page setup, i just reduce left and right margins to 0.25 from 1 each.

I don't want to do it every time I view and print a report. Is there a way to change these setting programmatically in C# or change the default page layout?


回答1:


you can use below code:

 System.Drawing.Printing.PageSettings pg=new System.Drawing.Printing.PageSettings();
 pg.Margins.Top = 0;
 pg.Margins.Bottom = 0;
 pg.Margins.Left = 0;
 pg.Margins.Right = 0;
 System.Drawing.Printing.PaperSize size = new PaperSize();
 size.RawKind = (int)PaperKind.A5;
 pg.PaperSize = size;
 reportViewer1.SetPageSettings(pg);
 this.reportViewer1.RefreshReport();



回答2:


Use pg.LandScape = true along with you existing,

    pg.Margins.Top = 0;
    pg.Margins.Bottom = 0;
    pg.Margins.Left = 0;
    pg.Margins.Right = 0; 
    pg.LandScape = true



回答3:


ReportViewer rpt = new ReportViewer();
rpt.SetPageSettings(new System.Drawing.Printing.PageSettings() { Landscape = true });


来源:https://stackoverflow.com/questions/12985990/set-page-layout-for-report-viewer-in-visual-studio-2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!