【发布时间】:2013-04-09 12:09:01
【问题描述】:
我正在枚举 PC 中连接的打印机。我使用 C# System.Printing 命名空间完成了它。
它运作良好。但主要是显示软件打印机,如 Microsoft XPS Document writer、Microsoft Fax 等。我想知道是否可以从枚举中删除这些软件打印机。我所做的代码如下所示:
PrintQueue printQueue = null;
LocalPrintServer localPrintServer = new LocalPrintServer();
// Retrieving collection of local printer on user machine
PrintQueueCollection localPrinterCollection =
localPrintServer.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local,
EnumeratedPrintQueueTypes.Connections });
System.Collections.IEnumerator localPrinterEnumerator =
localPrinterCollection.GetEnumerator();
while (localPrinterEnumerator.MoveNext())
{
// Get PrintQueue from first available printer
printQueue = (PrintQueue)localPrinterEnumerator.Current;
if (!printQueue.IsOffline)
{
MessageBox.Show(printQueue.FullName.ToString());
string s = "Printer found " + printQueue.FullName.ToString();
listBox1.Items.Add(s);
}
else
{
// No printer exist, return null PrintTicket
// return null;
}
}
【问题讨论】: