Export (0) Print
Expand All

PrinterSettings Class

Specifies information about how a document is printed, including the printer that prints it.

For a list of all members of this type, see PrinterSettings Members.

System.Object
   System.Drawing.Printing.PrinterSettings

[Visual Basic]
<Serializable>
<ComVisible(False)>
Public Class PrinterSettings
   Implements ICloneable
[C#]
[Serializable]
[ComVisible(false)]
public class PrinterSettings : ICloneable
[C++]
[Serializable]
[ComVisible(false)]
public __gc class PrinterSettings : public ICloneable
[JScript]
public
   Serializable
 ComVisible(false)
class PrinterSettings 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

Typically, you access a PrinterSettings through PrintDocument.PrinterSettings or PageSettings.PrinterSettings properties to modify printer settings. The most common printer setting is PrinterName, which specifies the printer to print to.

For more information on printing, see the System.Drawing.Printing namespace overview.

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(printer As String)
    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

            If pd.PrinterSettings.IsValid then
               pd.Print()
            Else
               MessageBox.Show("Printer is invalid.")
            End If
        Finally
            streamToPrint.Close()
        End Try
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try
End Sub
   

[C#] 
public void Printing(string printer) {
  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;

      if (pd.PrinterSettings.IsValid) {
         pd.Print();
      } 
      else {    
         MessageBox.Show("Printer is invalid.");
      }
    } 
    finally {
      streamToPrint.Close();
    }
  } 
  catch(Exception ex) {
    MessageBox.Show(ex.Message);
  }
}


[C++] 
public:
 void Printing(String* printer) {
   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;

       if (pd->PrinterSettings->IsValid) {
          pd->Print();
       } 
       else {    
          MessageBox::Show(S"Printer is invalid.");
       }
     } 
     __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

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

PrinterSettings Members | System.Drawing.Printing Namespace | PrinterName | PrintDocument.PrinterSettings | PageSettings.PrinterSettings

Show:
© 2015 Microsoft