Page Settings

You may have noticed that both the MarginBounds and the PageSettings properties of the PrintPageEventArgs class are read-only. Changing PageSettings on-the-fly (including the margins) requires handling the print document's QueryPageSettings event:

					void printDocument1_QueryPageSettings(
					object sender, QueryPageSettingsEventArgs e) {
  // Set margins to 0.5" all the way around
  // (measured in 100ths of an inch)
  e.PageSettings.Margins = new Margins(50, 50, 50, 50);
}
				

QueryPageSettingsEventArgs provides only a Cancel property and a PageSettings property. The latter is an instance of the PageSettings class:

 class PageSettings : ICloneable { // Constructors public PageSettings(); public PageSettings(PrinterSettings printerSettings); ...

Get Windows Forms Programming in C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.