set page layout for report viewer in visual studio

2019-03-09 17:12发布

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?

3条回答
欢心
2楼-- · 2019-03-09 17:31
ReportViewer rpt = new ReportViewer();
rpt.SetPageSettings(new System.Drawing.Printing.PageSettings() { Landscape = true });
查看更多
冷血范
3楼-- · 2019-03-09 17:32

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();
查看更多
贼婆χ
4楼-- · 2019-03-09 17:46

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
查看更多
登录 后发表回答