我正在枚举 PC 中连接的打印机。我使用 C#System.Printing
命名空间完成了它。它运作良好。但大多数情况下,它会显示Microsoft XPS Document writer、Microsoft Fax等软件打印机。我想知道是否可以从枚举中删除这些 ssoftware 打印机。我所做的代码如下所示:
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;
}
}