LocalPrintServer.GetDefaultPrintQueue 方法

定义

返回对 LocalPrintServer 的默认打印队列的引用。

public:
 static System::Printing::PrintQueue ^ GetDefaultPrintQueue();
public static System.Printing.PrintQueue GetDefaultPrintQueue ();
static member GetDefaultPrintQueue : unit -> System.Printing.PrintQueue
Public Shared Function GetDefaultPrintQueue () As PrintQueue

返回

默认的 PrintQueue

示例

下面的示例演示如何在运行时使用此方法在运行时发现打印队列的属性和这些属性的类型,而无需使用反射。


// Enumerate the properties, and their types, of a queue without using Reflection
LocalPrintServer localPrintServer = new LocalPrintServer();
PrintQueue defaultPrintQueue = LocalPrintServer.GetDefaultPrintQueue();

PrintPropertyDictionary printQueueProperties = defaultPrintQueue.PropertiesCollection;

Console.WriteLine("These are the properties, and their types, of {0}, a {1}", defaultPrintQueue.Name, defaultPrintQueue.GetType().ToString() +"\n");

foreach (DictionaryEntry entry in printQueueProperties)
{
    PrintProperty property = (PrintProperty)entry.Value;

    if (property.Value != null)
    {
        Console.WriteLine(property.Name + "\t(Type: {0})", property.Value.GetType().ToString());
    }
}
Console.WriteLine("\n\nPress Return to continue...");
Console.ReadLine();

' Enumerate the properties, and their types, of a queue without using Reflection
Dim localPrintServer As New LocalPrintServer()
Dim defaultPrintQueue As PrintQueue = LocalPrintServer.GetDefaultPrintQueue()

Dim printQueueProperties As PrintPropertyDictionary = defaultPrintQueue.PropertiesCollection

Console.WriteLine("These are the properties, and their types, of {0}, a {1}", defaultPrintQueue.Name, defaultPrintQueue.GetType().ToString() + vbLf)

For Each entry As DictionaryEntry In printQueueProperties
    Dim [property] As PrintProperty = CType(entry.Value, PrintProperty)

    If [property].Value IsNot Nothing Then
        Console.WriteLine([property].Name & vbTab & "(Type: {0})", [property].Value.GetType().ToString())
    End If
Next entry
Console.WriteLine(vbLf & vbLf & "Press Return to continue...")
Console.ReadLine()

注解

即使你有权AdministrateServer访问打印服务器,应用程序也只能UsePrinter访问默认队列。 若要以更高的访问权限打开队列,请使用可用于指定所需访问级别的构造函数之一 PrintQueue

适用于