我需要一个不直接打印的打印机列表。直接打印列表似乎相当容易。但是如何做相反的事情呢?
Dim PrintServer As New SysPrint.PrintServer
Dim arrFlags(0) As SysPrint.EnumeratedPrintQueueTypes
arrFlags(0) = System.Printing.EnumeratedPrintQueueTypes.DirectPrinting
Dim QColl As SysPrint.PrintQueueCollection = PrintServer.GetPrintQueues(arrFlags)
PrintServer.GetPrintQueues方法
EnumeratedPrintQueueTypes枚举
MSDN表示,EnumeratedPrintQueueTypes具有FlagsAttribute属性,该属性允许按位组合其成员值。所以我应该能够以某种方式指定NOT direct。我该怎么做?
我试着做这个arrFlags(0) = Not System.Printing.EnumeratedPrintQueueTypes.DirectPrinting
,但没有结果。显然不正确。
那么,如何操作flags属性以消除所有打印机直接打印呢?
这是一种方法,但看起来很不雅:
'get full list
Dim PrintServer As New SysPrint.PrintServer
Dim QColl As SysPrint.PrintQueueCollection = PrintServer.GetPrintQueues()
'get those not printing direct
Dim Qcoll2 As List(Of SysPrint.PrintQueue) = QColl.Where(Function(x) Not (x.IsDirect)).ToList
'select name only
Dim strList As List(Of String) = Qcoll2.Select(Function(x) x.Name).ToList