Winform Reports for .NET
   Home
   Product Comparison
   Products
     PrintForm .NET
     PrintControls .NET
     PrintAdapters .NET
     PrintPreviewDialog .NET
     Localizer ASP.NET
     WebExtenders ASP.NET
   Downloads
     Free Trial Versions
     Upgrades
   Documents & Papers
   Purchase
   Support Index
   Press Releases
   Contact Us
   Privacy Statement
 
 
 
Go to TMG Development Ltd Website
Microsoft Certified Partner

HowTo: Set the Margins and Landscape PageSettings for a PrintDocument

ID: W3298006

 

Background

This document describes how to use the .NET Framework PageSettings object to control the Margins and Landscape settings of any PrintDocument derived class.

Applies to :

  • PrintDocument
  • PrintForm
  • PrintAdapters: PrintListView, PrintRichTextBox, PrintTreeView and PrintDataTable
  • PrintChainManager

Adjusting properties of the PageSettings Object

Margin widths are controlled by the Margins property of the PageSettings object, and page orientation is controlled by the Landscape setting.

In the printing lifecycle of a PrintDocument there are two opportunities to set the PageSettings

  1. set the PrintDocument.DefaultPageSettings properties to control the default margin size etc of all pages printed by the PrintDocument, or
  2. set e.PageSettings.Margins in the PrintDocument.QueryPageSettings event to set each printed page's settings individually

 

Setting the default size for all pages in the form Load event via the DefaultPageSettings property:

VB.NET Sample, showing setting the Margins and Landscape for a PrintForm PrintDocument:

Private Sub frmSimpleForm_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
  Dim newMargins As System.Drawing.Printing.Margins
  newMargins = New System.Drawing.Printing.Margins(20, 20, 20, 20)
  Me.PrintForm1.DefaultPageSettings.Margins = newMargins
  Me.PrintForm1.DefaultPageSettings.Landscape = True
End Sub

Setting each page's Margin size individually via the QueryPageSettingsEventArgs.PageSettings property in the QueryPageSettings event:

VB.NET Sample, showing setting the Margins and Landscape for a PrintForm PrintDocument in the QueryPageSettings event:

Private Sub PrintForm1_QueryPageSettings(ByVal sender As Object, _
ByVal e As System.Drawing.Printing.QueryPageSettingsEventArgs) Handles PrintForm1.QueryPageSettings
  Dim newMargins As System.Drawing.Printing.Margins
  newMargins = New System.Drawing.Printing.Margins(20, 20, 20, 20)
  e.PageSettings.Margins = newMargins
  e.PageSettings.Landscape = True
End Sub

Last updated 04-Aug-2019