当前位置:编程学习 > C#/ASP.NET >>

C#获取本地打印机

 工作中遇到打印机的问题了,所以想到用C#代码来获取打印机信息,代码如下:
  private static PrintDocument fPrintDocument = new PrintDocument();
  /// <summary>
  /// Fetch local printer name.
  /// </summary>
  public static string DefaultPrinter
  {
  get
  {
  return fPrintDocument.PrinterSettings.PrinterName;
  }
  }
  /// <summary>
  /// fetch printer list of the machine,the first list is the default item.
  /// </summary>
  /// <returns></returns>
  public static List<string> GetLocalPrinters()
  {
  List<string> fPrinters = new List<string>();
  fPrinters.Add(DefaultPrinter);
  foreach (string fPrinterName in PrinterSettings.InstalledPrinters)
  {
  if (!fPrinters.Contains(fPrinterName))
  fPrinters.Add(fPrinterName);
  }
  return fPrinters;
  }

补充:软件开发 , C# ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,