PrintPropertyDictionary 類別

定義

表示與 System.Printing 命名空間中的物件關聯之屬性與值的集合。Represents a collection of properties and values that are associated with an object in the System.Printing namespace.

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

範例

下列範例示範如何使用這個類別,從現有的印表機,只在位置、埠和共用狀態中,安裝不同于其屬性的第二個印表機。The following example shows how to use this class to install a second printer that differs in its properties from an existing printer only in location, port, and shared status.

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

下列範例顯示如何使用這個類別,在執行時間探索列印系統物件的屬性,以及這些屬性的類型,而不使用反映。The following example shows how to use this class to discover at run time the properties, and the types of those properties, of a print system object, without using reflection.


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

備註

集合會採用 Hashtable 字典的形式。The collection takes the form of a Hashtable dictionary. 集合中每個 DictionaryEntryValue 屬性,都是衍生自 PrintProperty之類別的實例。The Value property of each DictionaryEntry in the collection is an instance of a class that is derived from PrintProperty.

建構函式

PrintPropertyDictionary()

初始化 PrintPropertyDictionary 類別的新執行個體。Initializes a new instance of the PrintPropertyDictionary class.

PrintPropertyDictionary(SerializationInfo, StreamingContext)

使用指定的 PrintPropertyDictionarySerializationInfo,初始化並提供 StreamingContext 類別的新執行個體。Initializes a new instance of the PrintPropertyDictionary class and provides it with the specified SerializationInfo and StreamingContext.

屬性

comparer

Gets or sets the IComparer to use for the Hashtable.Gets or sets the IComparer to use for the Hashtable.

(繼承來源 Hashtable)
Count

Gets the number of key/value pairs contained in the Hashtable.Gets the number of key/value pairs contained in the Hashtable.

(繼承來源 Hashtable)
EqualityComparer

Gets the IEqualityComparer to use for the Hashtable.Gets the IEqualityComparer to use for the Hashtable.

(繼承來源 Hashtable)
hcp

Gets or sets the object that can dispense hash codes.Gets or sets the object that can dispense hash codes.

(繼承來源 Hashtable)
IsFixedSize

Gets a value indicating whether the Hashtable has a fixed size.Gets a value indicating whether the Hashtable has a fixed size.

(繼承來源 Hashtable)
IsReadOnly

Gets a value indicating whether the Hashtable is read-only.Gets a value indicating whether the Hashtable is read-only.

(繼承來源 Hashtable)
IsSynchronized

Gets a value indicating whether access to the Hashtable is synchronized (thread safe).Gets a value indicating whether access to the Hashtable is synchronized (thread safe).

(繼承來源 Hashtable)
Item[Object]

Gets or sets the value associated with the specified key.Gets or sets the value associated with the specified key.

(繼承來源 Hashtable)
Keys

Gets an ICollection containing the keys in the Hashtable.Gets an ICollection containing the keys in the Hashtable.

(繼承來源 Hashtable)
SyncRoot

Gets an object that can be used to synchronize access to the Hashtable.Gets an object that can be used to synchronize access to the Hashtable.

(繼承來源 Hashtable)
Values

Gets an ICollection containing the values in the Hashtable.Gets an ICollection containing the values in the Hashtable.

(繼承來源 Hashtable)

方法

Add(Object, Object)

Adds an element with the specified key and value into the Hashtable.Adds an element with the specified key and value into the Hashtable.

(繼承來源 Hashtable)
Add(PrintProperty)

將指定物件 (屬於衍生自 PrintProperty 的類別) 加入字典。Adds the specified object (of a class that is derived from PrintProperty) into the dictionary.

Clear()

Removes all elements from the Hashtable.Removes all elements from the Hashtable.

(繼承來源 Hashtable)
Clone()

Creates a shallow copy of the Hashtable.Creates a shallow copy of the Hashtable.

(繼承來源 Hashtable)
Contains(Object)

Determines whether the Hashtable contains a specific key.Determines whether the Hashtable contains a specific key.

(繼承來源 Hashtable)
ContainsKey(Object)

Determines whether the Hashtable contains a specific key.Determines whether the Hashtable contains a specific key.

(繼承來源 Hashtable)
ContainsValue(Object)

Determines whether the Hashtable contains a specific value.Determines whether the Hashtable contains a specific value.

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

Copies the Hashtable elements to a one-dimensional Array instance at the specified index.Copies the Hashtable elements to a one-dimensional Array instance at the specified index.

(繼承來源 Hashtable)
Dispose()

釋放 PrintPropertyDictionary 正在使用的所有資源。Releases all the resources that are being used by the PrintPropertyDictionary.

Dispose(Boolean)

釋放 PrintPropertyDictionary 正在使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。Releases the unmanaged resources that are being used by the PrintPropertyDictionary and optionally releases the managed resources.

Equals(Object)

Determines whether the specified object is equal to the current object.Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetEnumerator()

Returns an IDictionaryEnumerator that iterates through the Hashtable.Returns an IDictionaryEnumerator that iterates through the Hashtable.

(繼承來源 Hashtable)
GetHash(Object)

Returns the hash code for the specified key.Returns the hash code for the specified key.

(繼承來源 Hashtable)
GetHashCode()

Serves as the default hash function.Serves as the default hash function.

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

以序列化 SerializationInfo 所需的資料填入 PrintPropertyDictionaryPopulates a SerializationInfo with the data that is needed to serialize the PrintPropertyDictionary.

GetProperty(String)

取得表示指定屬性的物件 (屬於衍生自 PrintProperty 的類別)。Gets the object (of a class that is derived from PrintProperty) that represents the specified property.

GetType()

Gets the Type of the current instance.Gets the Type of the current instance.

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

Compares a specific Object with a specific key in the Hashtable.Compares a specific Object with a specific key in the Hashtable.

(繼承來源 Hashtable)
MemberwiseClone()

Creates a shallow copy of the current Object.Creates a shallow copy of the current Object.

(繼承來源 Object)
OnDeserialization(Object)

實作 ISerializable 介面,並於還原序列化完成時引發還原序列化事件。Implements the ISerializable interface and raises the deserialization event when the deserialization is complete.

Remove(Object)

Removes the element with the specified key from the Hashtable.Removes the element with the specified key from the Hashtable.

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

將指定屬性的值設定為某個屬於 PrintProperty 所衍生類別的物件。Sets the value of the specified attribute to an object of a class that is derived from PrintProperty.

ToString()

Returns a string that represents the current object.Returns a string that represents the current object.

(繼承來源 Object)

明確介面實作

IEnumerable.GetEnumerator()

Returns an enumerator that iterates through a collection.Returns an enumerator that iterates through a collection.

(繼承來源 Hashtable)

擴充方法

Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

啟用查詢的平行化作業。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryableConverts an IEnumerable to an IQueryable.

適用於