PrintDocument.PrinterSettings 属性

获取或设置对文档进行打印的打印机。

**命名空间:**System.Drawing.Printing
**程序集:**System.Drawing(在 system.drawing.dll 中)

语法

声明
Public Property PrinterSettings As PrinterSettings
用法
Dim instance As PrintDocument
Dim value As PrinterSettings

value = instance.PrinterSettings

instance.PrinterSettings = value
public PrinterSettings PrinterSettings { get; set; }
public:
property PrinterSettings^ PrinterSettings {
    PrinterSettings^ get ();
    void set (PrinterSettings^ value);
}
/** @property */
public PrinterSettings get_PrinterSettings ()

/** @property */
public void set_PrinterSettings (PrinterSettings value)
public function get PrinterSettings () : PrinterSettings

public function set PrinterSettings (value : PrinterSettings)

属性值

PrinterSettings,它指定在何处以及如何打印文档。默认为 PrinterSettings,其属性均设置为默认值。

备注

可以通过 PrinterSettings 属性来指定几种打印机设置。例如,使用 PrinterSettings.Copies 属性来指定想要打印的份数,使用 PrinterSettings.PrinterName 属性来指定要使用的打印机,而使用 PrinterSettings.PrintRange 属性来指定想要打印的页的范围。

示例

下面的代码示例在指定的打印机上打印文档。该示例有三个假定:已经将名为 filePath 的变量设置为要打印的文件的路径;已经定义名为 pd_PrintPage 的方法(该方法处理 PrintPage 事件);已经将名为 printer 的变量设置为打印机的名称。

在此示例中使用 System.DrawingSystem.Drawing.PrintingSystem.IO 命名空间。

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    
   
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:
   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.add_PrintPage(new PrintPageEventHandler(pd_PrintPage));

            // Specify the printer to use.
            pd.get_PrinterSettings().set_PrinterName(printer);
            pd.Print();
        }
        finally {
            streamToPrint.Close();
        }
    }
    catch (System.Exception ex) {
        MessageBox.Show(ex.get_Message());
    }
} //Printing

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

PrintDocument 类
PrintDocument 成员
System.Drawing.Printing 命名空间
PrintDocument.DefaultPageSettings 属性
PrintDocument.DocumentName 属性
PrintDocument.PrintController 属性
PrinterSettings