PrintPropertyDictionary 類別

定義

表示與 System.Printing 命名空間中的物件關聯之屬性與值的集合。

public ref class PrintPropertyDictionary : System::Collections::Hashtable, IDisposable
public ref class PrintPropertyDictionary : System::Collections::Hashtable, IDisposable, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
[System.Serializable]
public class PrintPropertyDictionary : System.Collections.Hashtable, IDisposable
public class PrintPropertyDictionary : System.Collections.Hashtable, IDisposable, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
public class PrintPropertyDictionary : System.Collections.Hashtable, IDisposable
[<System.Serializable>]
type PrintPropertyDictionary = class
    inherit Hashtable
    interface ISerializable
    interface IDeserializationCallback
    interface IDisposable
type PrintPropertyDictionary = class
    inherit Hashtable
    interface IDisposable
    interface IDeserializationCallback
    interface ISerializable
Public Class PrintPropertyDictionary
Inherits Hashtable
Implements IDisposable
Public Class PrintPropertyDictionary
Inherits Hashtable
Implements IDeserializationCallback, IDisposable, ISerializable
繼承
PrintPropertyDictionary
屬性
實作

範例

下列範例示範如何使用這個類別來安裝第二部印表機,其屬性與現有印表機不同的位置、埠和共用狀態。

LocalPrintServer myLocalPrintServer = new LocalPrintServer(PrintSystemDesiredAccess.AdministrateServer);
PrintQueue sourcePrintQueue = myLocalPrintServer.DefaultPrintQueue;
PrintPropertyDictionary myPrintProperties = sourcePrintQueue.PropertiesCollection;

// Share the new printer using Remove/Add methods
PrintBooleanProperty shared = new PrintBooleanProperty("IsShared", true);
myPrintProperties.Remove("IsShared");
myPrintProperties.Add("IsShared", shared);

// Give the new printer its share name using SetProperty method
PrintStringProperty theShareName = new PrintStringProperty("ShareName", "\"Son of " + sourcePrintQueue.Name +"\"");
myPrintProperties.SetProperty("ShareName", theShareName);

// Specify the physical location of the new printer using Remove/Add methods
PrintStringProperty theLocation = new PrintStringProperty("Location", "the supply room");
myPrintProperties.Remove("Location");
myPrintProperties.Add("Location", theLocation);

// Specify the port for the new printer
String[] port = new String[] { "COM1:" };

// Install the new printer on the local print server
PrintQueue clonedPrinter = myLocalPrintServer.InstallPrintQueue("My clone of " + sourcePrintQueue.Name, "Xerox WCP 35 PS", port, "WinPrint", myPrintProperties);
myLocalPrintServer.Commit();

// Report outcome
Console.WriteLine("{0} in {1} has been installed and shared as {2}", clonedPrinter.Name, clonedPrinter.Location, clonedPrinter.ShareName);
Console.WriteLine("Press Return to continue ...");
Console.ReadLine();
Dim myLocalPrintServer As New LocalPrintServer(PrintSystemDesiredAccess.AdministrateServer)
Dim sourcePrintQueue As PrintQueue = myLocalPrintServer.DefaultPrintQueue
Dim myPrintProperties As PrintPropertyDictionary = sourcePrintQueue.PropertiesCollection

' Share the new printer using Remove/Add methods
Dim [shared] As New PrintBooleanProperty("IsShared", True)
myPrintProperties.Remove("IsShared")
myPrintProperties.Add("IsShared", [shared])

' Give the new printer its share name using SetProperty method
Dim theShareName As New PrintStringProperty("ShareName", """Son of " & sourcePrintQueue.Name & """")
myPrintProperties.SetProperty("ShareName", theShareName)

' Specify the physical location of the new printer using Remove/Add methods
Dim theLocation As New PrintStringProperty("Location", "the supply room")
myPrintProperties.Remove("Location")
myPrintProperties.Add("Location", theLocation)

' Specify the port for the new printer
Dim port() As String = { "COM1:" }


' Install the new printer on the local print server
Dim clonedPrinter As PrintQueue = myLocalPrintServer.InstallPrintQueue("My clone of " & sourcePrintQueue.Name, "Xerox WCP 35 PS", port, "WinPrint", myPrintProperties)
myLocalPrintServer.Commit()

' Report outcome
Console.WriteLine("{0} in {1} has been installed and shared as {2}", clonedPrinter.Name, clonedPrinter.Location, clonedPrinter.ShareName)
Console.WriteLine("Press Return to continue ...")
Console.ReadLine()

下列範例示範如何使用這個類別在執行時間探索屬性,以及列印系統物件的這些屬性類型,而不使用反映。


// 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()

備註

集合採用字典的形式 HashtableValue集合中每個 DictionaryEntry 屬性都是衍生自 PrintProperty 的類別實例。

建構函式

PrintPropertyDictionary()

初始化 PrintPropertyDictionary 類別的新執行個體。

PrintPropertyDictionary(SerializationInfo, StreamingContext)

使用指定的 PrintPropertyDictionarySerializationInfo,初始化並提供 StreamingContext 類別的新執行個體。

屬性

comparer
已過時。
已過時。

取得或設定 IComparer 所使用的 Hashtable

(繼承來源 Hashtable)
Count

取得 Hashtable 中所包含的索引鍵/值組數目。

(繼承來源 Hashtable)
EqualityComparer

取得 IEqualityComparer 所使用的 Hashtable

(繼承來源 Hashtable)
hcp
已過時。
已過時。

取得或設定可以分配雜湊程式碼的物件。

(繼承來源 Hashtable)
IsFixedSize

取得值,指出 Hashtable 是否有固定的大小。

(繼承來源 Hashtable)
IsReadOnly

取得值,指出 Hashtable 是否唯讀。

(繼承來源 Hashtable)
IsSynchronized

取得值,這個值表示對 Hashtable 的存取是否同步 (安全執行緒)。

(繼承來源 Hashtable)
Item[Object]

取得或設定與指定之索引鍵相關聯的值。

(繼承來源 Hashtable)
Keys

取得含有 ICollection 中的索引鍵的 Hashtable

(繼承來源 Hashtable)
SyncRoot

取得可用以同步存取 Hashtable 的物件。

(繼承來源 Hashtable)
Values

取得 ICollection,包含 Hashtable 中的值。

(繼承來源 Hashtable)

方法

Add(Object, Object)

將有指定索引鍵和數值的項目加入 Hashtable

(繼承來源 Hashtable)
Add(PrintProperty)

將指定物件 (屬於衍生自 PrintProperty 的類別) 加入字典。

Clear()

移除 Hashtable 中的所有項目。

(繼承來源 Hashtable)
Clone()

建立 Hashtable 的淺層複本。

(繼承來源 Hashtable)
Contains(Object)

判斷 Hashtable 是否包含特定索引鍵。

(繼承來源 Hashtable)
ContainsKey(Object)

判斷 Hashtable 是否包含特定索引鍵。

(繼承來源 Hashtable)
ContainsValue(Object)

判斷 Hashtable 是否包含特定值。

(繼承來源 Hashtable)
CopyTo(Array, Int32)

Hashtable 元素複製到指定索引的一維 Array 執行個體。

(繼承來源 Hashtable)
Dispose()

釋放 PrintPropertyDictionary 正在使用的所有資源。

Dispose(Boolean)

釋放 PrintPropertyDictionary 正在使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetEnumerator()

傳回透過 IDictionaryEnumerator 重複的 Hashtable

(繼承來源 Hashtable)
GetHash(Object)

傳回指定索引鍵的雜湊程式碼。

(繼承來源 Hashtable)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetObjectData(SerializationInfo, StreamingContext)

以序列化 SerializationInfo 所需的資料填入 PrintPropertyDictionary

GetProperty(String)

取得表示指定屬性的物件 (屬於衍生自 PrintProperty 的類別)。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
KeyEquals(Object, Object)

比較特定的 ObjectHashtable 中的特定索引鍵。

(繼承來源 Hashtable)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
OnDeserialization(Object)

實作 ISerializable 介面,並於還原序列化完成時引發還原序列化事件。

Remove(Object)

將有指定索引鍵的項目從 Hashtable 移除。

(繼承來源 Hashtable)
SetProperty(String, PrintProperty)

將指定屬性的值設定為某個屬於 PrintProperty 所衍生類別的物件。

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

IEnumerable.GetEnumerator()

傳回逐一查看集合的列舉值。

(繼承來源 Hashtable)

擴充方法

Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。

OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。

AsParallel(IEnumerable)

啟用查詢的平行化作業。

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryable

適用於