[C# Helper]
Index Books FAQ Contact About Rod
[Beginning Database Design Solutions, Second Edition]

[Beginning Software Engineering, Second Edition]

[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: Change print orientation and margins in C#

[Change print orientation and margins in C#]

This example shows how to change the print orientation and margins in a printout or print preview.

By default, when you display a print preview or print a document, the document appears in portrait orientation with one inch margins. To change that, set the PrintDocument object's DefaultPageSettings properties before displaying the preview as in the following code.

// Display the print preview. private void btnGo_Click(object sender, EventArgs e) { pdocTriangle.DefaultPageSettings.Margins = new System.Drawing.Printing.Margins(50, 50, 50, 50); pdocTriangle.DefaultPageSettings.Landscape = true; ppdTriangle.ShowDialog(); }

This code sets the page's margins to half inch (measured in hundredths of inches). It changes the print orientation by setting the Landscape property to true. The code then displays the print preview dialog as usual.

That's all there is to it! The result is a preview that is displayed with the landscape print orientation and with 1/2 inch margins.

Download the example to experiment with it and to see additional details.

© 2009-2023 Rocky Mountain Computer Consulting, Inc. All rights reserved.