Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

PrintDocument.PrinterSettings Property

Gets or sets the printer that prints the document.

Namespace:  System.Drawing.Printing
Assembly:  System.Drawing (in System.Drawing.dll)
[BrowsableAttribute(false)]
public PrinterSettings PrinterSettings { get; set; }

Property Value

Type: System.Drawing.Printing.PrinterSettings
A PrinterSettings that specifies where and how the document is printed. The default is a PrinterSettings with its properties set to their default values.

You can specify several printer settings through the PrinterSettings property. For example, use the PrinterSettings.Copies property to specify the number of copies you want to print, the PrinterSettings.PrinterName property to specify the printer to use, and the PrinterSettings.PrintRange property to specify the range of pages you want to print.

The following code example prints a document on the specified printer. The example makes three assumptions: that a variable names 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.

Use the System.Drawing, System.Drawing.Printing, and System.IO namespaces for this example.

public void Printing()
{
  try
  {
     streamToPrint = new StreamReader (filePath);
     try
     {
        printFont = new Font("Arial", 10);
        PrintDocument pd = new PrintDocument(); 
        pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
        // Specify the printer to use.
        pd.PrinterSettings.PrinterName = printer;
        pd.Print();
     } 
     finally
     {
        streamToPrint.Close();
     }
  } 
  catch(Exception ex)
  { 
     MessageBox.Show(ex.Message);
  }
}

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.