set page layout for report viewer in visual studio 2010
Asked Answered
W

3

13

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?

Wilsonwilt answered 20/10, 2012 at 6:44 Comment(0)
U
21

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();
Ulland answered 25/10, 2012 at 20:55 Comment(2)
what if i wanted to use a custom paper size?Explanatory
@smith This link may help you. #2014130Ulland
H
3

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
Headspring answered 31/10, 2012 at 6:12 Comment(0)
M
2
ReportViewer rpt = new ReportViewer();
rpt.SetPageSettings(new System.Drawing.Printing.PageSettings() { Landscape = true });
Meneau answered 26/1, 2015 at 12:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.