工作中遇到打印機的問題了,所以想到用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;
}