Samarth Agarwal
Samarth Agarwal

Reputation: 2134

set page layout for report viewer in visual studio 2010

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?

Upvotes: 13

Views: 40414

Answers (3)

alansiqueira27
alansiqueira27

Reputation: 8506

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

Upvotes: 3

Sivaraman
Sivaraman

Reputation: 458

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

Upvotes: 4

mjyazdani
mjyazdani

Reputation: 2035

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();

Upvotes: 22

Related Questions