This documentation is archived and is not being maintained.

PrintDocument.PrinterSettings Property

Gets or sets the printer that prints the document.

[Visual Basic]
Public Property PrinterSettings As PrinterSettings
[C#]
public PrinterSettings PrinterSettings {get; set;}
[C++]
public: __property PrinterSettings* get_PrinterSettings();
public: __property void set_PrinterSettings(PrinterSettings*);
[JScript]
public function get PrinterSettings() : PrinterSettings;
public function set PrinterSettings(PrinterSettings);

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.

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.

Note   The PrinterSettings.PrintToFile property can only be set by the System.Windows.Forms.Printing.PrintDialog class. The Print to file option only appears on the System.Windows.Forms.Printing.PrintDialog when the System.Windows.Forms.Printing.PrintDialog.AllowPrintToFile property is set to true. For more information, see the KB article "'PrintDocument Class' Does Not Implement The PrintToFile Feature (820644)" on Microsoft TechNet, at http://www.microsoft.com/technet.

Example

[Visual Basic, C#, C++] The following 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.

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


[C++] 
public:
 void Printing()
 {
   try
   {
      streamToPrint = new StreamReader (filePath);
      try
      {
         printFont = new System::Drawing::Font(S"Arial", 10);
         PrintDocument* pd = new PrintDocument(); 
         pd->PrintPage += new PrintPageEventHandler(this, &Form1::pd_PrintPage);
         // Specify the printer to use.
         pd->PrinterSettings->PrinterName = printer;
         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 Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

PrintDocument Class | PrintDocument Members | System.Drawing.Printing Namespace | DefaultPageSettings | DocumentName | PrintController | PrinterSettings

Show: