PrintPropertyDictionary Classe

Définition

Représente une collection de propriétés et de valeurs associées à un objet dans l'espace de noms 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
Héritage
PrintPropertyDictionary
Attributs
Implémente

Exemples

L’exemple suivant montre comment utiliser cette classe pour installer une deuxième imprimante qui diffère de ses propriétés d’une imprimante existante uniquement à l’emplacement, au port et à l’état partagé.

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

L’exemple suivant montre comment utiliser cette classe pour découvrir au moment de l’exécution les propriétés, ainsi que les types de ces propriétés, d’un objet système d’impression, sans utiliser de réflexion.


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

Remarques

La collection prend la forme d’un Hashtable dictionnaire. La Value propriété de chaque DictionaryEntry élément de la collection est une instance d’une classe dérivée de PrintProperty.

Constructeurs

PrintPropertyDictionary()

Initialise une nouvelle instance de la classe PrintPropertyDictionary.

PrintPropertyDictionary(SerializationInfo, StreamingContext)

Initialise une nouvelle instance de la classe PrintPropertyDictionary et lui fournit les SerializationInfo et StreamingContext spécifiés.

Propriétés

comparer
Obsolète.
Obsolète.

Obtient ou définit le IComparer à utiliser pour Hashtable.

(Hérité de Hashtable)
Count

Obtient le nombre de paires clé/valeur contenues dans Hashtable.

(Hérité de Hashtable)
EqualityComparer

Obtient le IEqualityComparer à utiliser pour Hashtable.

(Hérité de Hashtable)
hcp
Obsolète.
Obsolète.

Obtient ou définit l'objet qui peut dispenser des codes de hachage.

(Hérité de Hashtable)
IsFixedSize

Obtient une valeur indiquant si Hashtable est de taille fixe.

(Hérité de Hashtable)
IsReadOnly

Obtient une valeur indiquant si Hashtable est en lecture seule.

(Hérité de Hashtable)
IsSynchronized

Obtient une valeur indiquant si l’accès à Hashtable est synchronisé (thread-safe).

(Hérité de Hashtable)
Item[Object]

Obtient ou définit la valeur associée à la clé spécifiée.

(Hérité de Hashtable)
Keys

Obtient ICollection contenant les clés de Hashtable.

(Hérité de Hashtable)
SyncRoot

Obtient un objet qui peut être utilisé pour synchroniser l’accès à Hashtable.

(Hérité de Hashtable)
Values

Obtient ICollection contenant les valeurs de Hashtable.

(Hérité de Hashtable)

Méthodes

Add(Object, Object)

Ajoute un élément avec la clé et la valeur spécifiées dans Hashtable.

(Hérité de Hashtable)
Add(PrintProperty)

Ajoute l'objet spécifié (d'une classe dérivée de PrintProperty) au dictionnaire.

Clear()

Supprime tous les éléments de Hashtable.

(Hérité de Hashtable)
Clone()

Crée une copie superficielle de Hashtable.

(Hérité de Hashtable)
Contains(Object)

Détermine si Hashtable contient une clé spécifique.

(Hérité de Hashtable)
ContainsKey(Object)

Détermine si Hashtable contient une clé spécifique.

(Hérité de Hashtable)
ContainsValue(Object)

Détermine si Hashtable contient une valeur spécifique.

(Hérité de Hashtable)
CopyTo(Array, Int32)

Copie les éléments Hashtable dans une instance de Array unidimensionnelle à l'index spécifié.

(Hérité de Hashtable)
Dispose()

Libère toutes les ressources utilisées par le PrintPropertyDictionary.

Dispose(Boolean)

Libère les ressources non managées utilisées par PrintPropertyDictionary et libère éventuellement les ressources managées.

Equals(Object)

Détermine si l'objet spécifié est égal à l'objet actuel.

(Hérité de Object)
GetEnumerator()

Retourne un IDictionaryEnumerator qui itère au sein de Hashtable.

(Hérité de Hashtable)
GetHash(Object)

Retourne le code de hachage pour la clé spécifiée.

(Hérité de Hashtable)
GetHashCode()

Fait office de fonction de hachage par défaut.

(Hérité de Object)
GetObjectData(SerializationInfo, StreamingContext)

Remplit une instance de SerializationInfo avec les données nécessaires pour sérialiser PrintPropertyDictionary.

GetProperty(String)

Obtient l'objet (d'une classe dérivée de PrintProperty) qui représente la propriété spécifiée.

GetType()

Obtient le Type de l'instance actuelle.

(Hérité de Object)
KeyEquals(Object, Object)

Compare un Object spécifique avec une clé spécifique dans Hashtable.

(Hérité de Hashtable)
MemberwiseClone()

Crée une copie superficielle du Object actuel.

(Hérité de Object)
OnDeserialization(Object)

Implémente l’interface ISerializable et déclenche l’événement de désérialisation une fois la désérialisation terminée.

Remove(Object)

Supprime de Hashtable l'élément ayant la clé spécifiée.

(Hérité de Hashtable)
SetProperty(String, PrintProperty)

Affecte à l'attribut spécifié la valeur d'un objet d'une classe dérivée de PrintProperty.

ToString()

Retourne une chaîne qui représente l'objet actuel.

(Hérité de Object)

Implémentations d’interfaces explicites

IEnumerable.GetEnumerator()

Retourne un énumérateur qui itère au sein d’une collection.

(Hérité de Hashtable)

Méthodes d’extension

Cast<TResult>(IEnumerable)

Effectue un cast des éléments d'un IEnumerable vers le type spécifié.

OfType<TResult>(IEnumerable)

Filtre les éléments d'un IEnumerable en fonction du type spécifié.

AsParallel(IEnumerable)

Active la parallélisation d'une requête.

AsQueryable(IEnumerable)

Convertit un IEnumerable en IQueryable.

S’applique à