Margins Class
Specifies the dimensions of the margins of a printed page.
Assembly: System.Drawing (in System.Drawing.dll)
The Margins class is used to manipulate the width of margins in PageSettings and PrintController. MarginsConverter is the type descriptor for this class.
Left, Right, Top, and Bottom are properties that define the margins. Clone creates an identical Margins. Equals determines if another object has the same dimensions as a Margins.
For more information about printing, see the System.Drawing.Printing namespace overview.
Use the System.Drawing, System.Drawing.Printing, and System.IO namespaces for this example.
The following code example sets the default page settings for a document to margins of 1 inch on each side.
Public Sub Printing() Try ' This assumes that a variable of type string, named filePath, ' has been set to the path of the file to print. streamToPrint = New StreamReader(filePath) Try printFont = New Font("Arial", 10) Dim pd As New PrintDocument() ' This assumes that a method, named pd_PrintPage, has been ' defined. pd_PrintPage handles the PrintPage event. AddHandler pd.PrintPage, AddressOf pd_PrintPage ' This assumes that a variable of type string, named ' printer, has been set to the printer's name. pd.PrinterSettings.PrinterName = printer ' Create a new instance of Margins with one inch margins. Dim margins As New Margins(100, 100, 100, 100) pd.DefaultPageSettings.Margins = margins pd.Print() Finally streamToPrint.Close() End Try Catch ex As Exception MessageBox.Show("An error occurred printing the file - " & ex.Message) End Try End Sub
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.