PageSettings Class
Specifies settings that apply to a single, printed page.
For a list of all members of this type, see PageSettings Members.
System.Object
System.Drawing.Printing.PageSettings
[Visual Basic] <ComVisible(False)> Public Class PageSettings Implements ICloneable [C#] [ComVisible(false)] public class PageSettings : ICloneable [C++] [ComVisible(false)] public __gc class PageSettings : public ICloneable [JScript] public ComVisible(false) class PageSettings implements ICloneable
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Remarks
This class is used to specify settings that modify the way a page will be printed. Typically, you set default settings for all pages to be printed through the PrintDocument.DefaultPageSettings property. To specify settings on a page-by-page basis, handle the PrintDocument.PrintPage or PrintDocument.QueryPageSettings event and modify the PageSettings argument included in the PrintPageEventArgs or QueryPageSettingsEventArgs, respectively.
For more information on handling PrintDocument events, see the PrintDocument class overview. For more information on printing, see the System.Drawing.Printing namespace overview.
Example
[Visual Basic, C#, C++] The following example sets the document's default page orientation to landscape through the PrintDocument.DefaultPageSettings property, and prints the document using the Print method. The example makes three assumptions: that a variable named filePath has been set to the path of the file to print; that a method named pd_PrintPage, which handles the PrintPage event, has been defined; and that a variable named printer has been set to the printer's name.
[Visual Basic, C#, C++] Use the System.Drawing, System.Drawing.Printing, and System.IO namespaces for this example.
[Visual Basic] Public Sub Printing() Try streamToPrint = New StreamReader(filePath) Try printFont = New Font("Arial", 10) Dim pd As New PrintDocument() AddHandler pd.PrintPage, AddressOf pd_PrintPage pd.PrinterSettings.PrinterName = printer ' Set the page orientation to landscape. pd.DefaultPageSettings.Landscape = True pd.Print() Finally streamToPrint.Close() End Try Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub [C#] public void Printing() { try { streamToPrint = new StreamReader (filePath); try { printFont = new Font("Arial", 10); PrintDocument pd = new PrintDocument(); pd.PrintPage += new PrintPageEventHandler(pd_PrintPage); pd.PrinterSettings.PrinterName = printer; // Set the page orientation to landscape. pd.DefaultPageSettings.Landscape = true; pd.Print(); } finally { streamToPrint.Close() ; } } catch(Exception ex) { MessageBox.Show(ex.Message); } } [C++] public: void Printing() { try { streamToPrint = new StreamReader (filePath); try { printFont = new Font(S"Arial", 10); PrintDocument* pd = new PrintDocument(); pd->PrintPage += new PrintPageEventHandler(this, &Sample::pd_PrintPage); pd->PrinterSettings->PrinterName = printer; // Set the page orientation to landscape. pd->DefaultPageSettings->Landscape = true; pd->Print(); } __finally { streamToPrint->Close() ; } } catch(Exception* ex) { MessageBox::Show(ex->Message); } }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Drawing.Printing
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: System.Drawing (in System.Drawing.dll)
See Also
PageSettings Members | System.Drawing.Printing Namespace | PrintDocument | PrinterSettings