PrintPropertyDictionary Classe

Definição

Representa uma coleção de propriedades e valores associados a um objeto no 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
[System.Serializable]
public class PrintPropertyDictionary : System.Collections.Hashtable, IDisposable
public class PrintPropertyDictionary : System.Collections.Hashtable, IDisposable
public class PrintPropertyDictionary : System.Collections.Hashtable, IDisposable, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
[<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
Herança
PrintPropertyDictionary
Atributos
Implementações

Exemplos

O exemplo seguinte mostra como usar esta classe para instalar uma segunda impressora que difere nas suas propriedades de uma impressora existente apenas na localização, porta e estado partilhado.

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

O exemplo seguinte mostra como usar esta classe para descobrir, em tempo de execução, as propriedades e os tipos dessas propriedades de um objeto do sistema de impressão, sem usar reflexão.


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

Observações

A coleção assume a forma de um Hashtable dicionário. A Value propriedade de cada DictionaryEntry na coleção é uma instância de uma classe derivada de PrintProperty.

Construtores

Name Description
PrintPropertyDictionary()

Inicializa uma nova instância da PrintPropertyDictionary classe.

PrintPropertyDictionary(SerializationInfo, StreamingContext)

Inicializa uma nova instância da PrintPropertyDictionary classe e fornece-lhe os especificados SerializationInfo e StreamingContext.

Propriedades

Name Description
comparer
Obsoleto.
Obsoleto.

Obtém ou define o IComparer para usar para o Hashtable.

(Herdado de Hashtable)
Count

Obtém o número de pares chave/valor contidos no Hashtable.

(Herdado de Hashtable)
EqualityComparer

Obtém o IEqualityComparer para usar para o Hashtable.

(Herdado de Hashtable)
hcp
Obsoleto.
Obsoleto.

Obtém ou define o objeto que pode dispensar códigos de hash.

(Herdado de Hashtable)
IsFixedSize

Obtém um valor que indica se o Hashtable tem um tamanho fixo.

(Herdado de Hashtable)
IsReadOnly

Recebe um valor que indica se o Hashtable é apenas de leitura.

(Herdado de Hashtable)
IsSynchronized

Recebe um valor que indica se o acesso ao Hashtable é sincronizado (thread safe).

(Herdado de Hashtable)
Item[Object]

Obtém ou define o valor associado à chave especificada.

(Herdado de Hashtable)
Keys

Obtém um ICollection contendo as chaves no Hashtable.

(Herdado de Hashtable)
SyncRoot

Obtém um objeto que pode ser usado para sincronizar o acesso ao Hashtable.

(Herdado de Hashtable)
Values

Obtém um ICollection contendo os valores em .Hashtable

(Herdado de Hashtable)

Métodos

Name Description
Add(Object, Object)

Adiciona um elemento com a chave e valor especificados no Hashtable.

(Herdado de Hashtable)
Add(PrintProperty)

Adiciona o objeto especificado (de uma classe derivada de PrintProperty) ao dicionário.

Clear()

Remove todos os elementos do Hashtable.

(Herdado de Hashtable)
Clone()

Cria uma cópia superficial do Hashtable.

(Herdado de Hashtable)
Contains(Object)

Determina se o Hashtable contém uma chave específica.

(Herdado de Hashtable)
ContainsKey(Object)

Determina se o Hashtable contém uma chave específica.

(Herdado de Hashtable)
ContainsValue(Object)

Determina se o Hashtable contém um valor específico.

(Herdado de Hashtable)
CopyTo(Array, Int32)

Copia os Hashtable elementos para uma instância unidimensional Array no índice especificado.

(Herdado de Hashtable)
Dispose()

Liberta todos os recursos que estão a ser usados pelo PrintPropertyDictionary.

Dispose(Boolean)

Liberta os recursos não geridos que estão a ser usados pelo PrintPropertyDictionary e, opcionalmente, liberta os recursos geridos.

Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.

(Herdado de Object)
GetEnumerator()

Retorna um IDictionaryEnumerator que itera através do Hashtable.

(Herdado de Hashtable)
GetHash(Object)

Devolve o código de hash da chave especificada.

(Herdado de Hashtable)
GetHashCode()

Serve como função de hash predefinida.

(Herdado de Object)
GetObjectData(SerializationInfo, StreamingContext)

Preenche a SerializationInfo com os dados necessários para serializar o PrintPropertyDictionary.

GetProperty(String)

Obtém o objeto (de uma classe derivada de PrintProperty) que representa a propriedade especificada.

GetType()

Obtém o Type da instância atual.

(Herdado de Object)
KeyEquals(Object, Object)

Compara uma chave específica Object com uma chave específica no Hashtable.

(Herdado de Hashtable)
MemberwiseClone()

Cria uma cópia superficial do atual Object.

(Herdado de Object)
OnDeserialization(Object)

Implementa a ISerializable interface e levanta o evento de desserialização quando a desserialização está concluída.

Remove(Object)

Remove o elemento com a chave especificada da Hashtable.

(Herdado de Hashtable)
SetProperty(String, PrintProperty)

Define o valor do atributo especificado para um objeto de uma classe derivada de PrintProperty.

ToString()

Devolve uma cadeia que representa o objeto atual.

(Herdado de Object)

Implementações de Interface Explícita

Name Description
IEnumerable.GetEnumerator()

Devolve um enumerador que itera numa coleção.

(Herdado de Hashtable)

Métodos da Extensão

Name Description
AsParallel(IEnumerable)

Permite a paralelização de uma consulta.

AsQueryable(IEnumerable)

Converte um IEnumerable para um IQueryable.

Cast<TResult>(IEnumerable)

Conjura os elementos de an IEnumerable para o tipo especificado.

OfType<TResult>(IEnumerable)

Filtra os elementos de um IEnumerable com base num tipo especificado.

Aplica-se a