Επεξεργασία

Κοινή χρήση μέσω


PrintDocument.PrinterSettings Property

Definition

Gets or sets the printer that prints the document.

public:
 property System::Drawing::Printing::PrinterSettings ^ PrinterSettings { System::Drawing::Printing::PrinterSettings ^ get(); void set(System::Drawing::Printing::PrinterSettings ^ value); };
[System.ComponentModel.Browsable(false)]
public System.Drawing.Printing.PrinterSettings PrinterSettings { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.PrinterSettings : System.Drawing.Printing.PrinterSettings with get, set
Public Property PrinterSettings As 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.

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.

public:
   void Printing()
   {
      try
      {
         streamToPrint = gcnew StreamReader( filePath );
         try
         {
            printFont = gcnew System::Drawing::Font( "Arial",10 );
            PrintDocument^ pd = gcnew PrintDocument;
            pd->PrintPage += gcnew 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 );
      }
   }
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);
  }
}
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

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

See also