C# 如何设置打印机属性

2025-11-04 18:12:23

1、命名空间:

System.Drawing.Printing

组件:

System.Drawing.dll程序,System.Drawing.Common.dll

C# 如何设置打印机属性

2、指定从Windows Form 应用程式列印时,文件如何列印的相关资讯,包括用来列印的印表机。

[System.Runtime.InteropServices.ComVisible(false)]

[Serializable]

public class PrinterSettings : ICloneable

C# 如何设置打印机属性

3、继承:

宾语

PrinterSettings

属性

ComVisibleAttribute  SerializableAttribute

实体

ICloneable

C# 如何设置打印机属性

4、下列程式码范例会在指定的印表机上列印文件。此范例包含三个必要条件:

名为的变数filePath已列印设定档案的路径。

名为的方法pd_PrintPage,以处理PrintPage已定义事件。

名为的变数printer已设为印表机的名称。

C# 如何设置打印机属性

5、使用System.Drawing,System.Drawing.Printing,和System.IO此范例中的命名空间。

6、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# 如何设置打印机属性

7、构建函数

PrinterSettings()初始化PrinterSettings类别的新执行个体

public PrinterSettings ();

8、打印机属性

C# 如何设置打印机属性

9、打印机 方法

C# 如何设置打印机属性

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢