PrintDocument.PrinterSettings Property

Definition

Gets or sets the printer that prints the document.

C#
[System.ComponentModel.Browsable(false)]
public System.Drawing.Printing.PrinterSettings PrinterSettings { get; set; }

Property Value

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

Attributes

Examples

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.

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);
        // Specify the printer to use.
        pd.PrinterSettings.PrinterName = printer;
        pd.Print();
     } 
     finally
     {
        streamToPrint.Close();
     }
  } 
  catch(Exception ex)
  { 
     MessageBox.Show(ex.Message);
  }
}

Remarks

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.

Applies to

Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also