Title: 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.
|