How to set page orientation to landscape?
How can I set the page orientation to landscape? I tried to set "printDocument.DefaultPageSettings.Landscape = true;" but it didn't work. I have spent hours fixing the problem but I couldn't get it work. Below is the code: private void printDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { e.HasMorePages = false; printDocument.DefaultPageSettings.Landscape = true; System.Drawing.Font printFont = new System.Drawing.Font("Arial", 12, System.Drawing.FontStyle.Regular); e.Graphics.DrawString("Set the page orientation to landscape!", printFont, System.Drawing.Brushes.Black, 30, 30, new StringFormat()); } Could someone please tell me what is wrong with it, or what I should do to get it work? Your help is very much appreciated. Thannks.
January 28th, 2007 5:07am

Hi.may be I didn't understand to problem but why not just change to report parametrs?right click on the report (empty space in the bottom)---> properties (be sure that in the "report" is selected) --> change the page side to "11in, 8.5in".That will change it to be sowen and printed in landscape.
Free Windows Admin Tool Kit Click here and download it now
January 28th, 2007 9:11am

Thanks Roy for the response, but I am not sure what report you are talking about. I don't use Crystal Report. Do I miss something here? By the way, I tried to override the PaperSize as shown below but it didn't seem to work. printDocument.PrinterSettings.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("Letter", 850, 1100); Thanks.
January 28th, 2007 8:41pm

Hi,I'm talking about a reporting services report.I'm using visual studio 2005 for creating my report. maybe you are useing something also?If you are useing vs2005 too, then check to report properties and change to report size like I wrote in the previuos post.If not - ttry to give us few more details.Take care,Roy.
Free Windows Admin Tool Kit Click here and download it now
January 29th, 2007 9:43am

Hi Roy, Thanks for your response.Forgive meif my question is unclear. Below is my reduced testcase to clarify my question. I hope it would clear up any confusion. Thank you again. using System.Drawing;using System.Drawing.Printing;using System;using System.Windows.Forms; namespace WindowsApplication1{ public class Form1 : Form { public Form1() { InitializeComponent(); } private void print_Click(object sender, EventArgs e) { printDocument.Print(); } private void printDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { e.HasMorePages = false; printDocument.DefaultPageSettings.Landscape = true; System.Drawing.Font printFont = new System.Drawing.Font("Arial", 12, System.Drawing.FontStyle.Regular); e.Graphics.DrawString("Set the page orientation to landscape!", printFont, System.Drawing.Brushes.Black, 30, 30, new StringFormat()); } private void InitializeComponent() { this.printButton = new System.Windows.Forms.Button(); this.printDialog = new System.Windows.Forms.PrintDialog(); this.printDocument = new System.Drawing.Printing.PrintDocument(); this.SuspendLayout(); // // printButton // this.printButton.Location = new System.Drawing.Point(199, 69); this.printButton.Name = "printButton"; this.printButton.Size = new System.Drawing.Size(75, 23); this.printButton.TabIndex = 0; this.printButton.Text = "Print"; this.printButton.Click += new System.EventHandler(this.print_Click); // // printDialog // this.printDialog.Document = this.printDocument; // // printDocument // this.printDocument.DocumentName = ""; this.printDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printDocument_PrintPage); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(499, 412); this.Controls.Add(this.printButton); this.Name = "Form1"; this.ResumeLayout(false); } private System.Windows.Forms.Button printButton; private System.Windows.Forms.PrintDialog printDialog; private System.Drawing.Printing.PrintDocument printDocument; static void Main() { Application.Run(new Form1()); } }}
January 29th, 2007 7:38pm

with visual studio 2010, i am able to set the page orientation to landscape just by right clicking below the report on the white space and selecting the report properties. this works well without writing any line of code.
Free Windows Admin Tool Kit Click here and download it now
July 8th, 2011 4:38am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics