Change print orientation and margins in C#

[print orientation]

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;

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 Example   Follow me on Twitter   RSS feed   Donate

This entry was posted in printing and tagged , , , , , , , , , . Bookmark the permalink.

1 Response to Change print orientation and margins in C#

  1. Anil Raina says:

    Thanks a lot Sir

Comments are closed.