PrintQueueCollection Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Represents a collection of PrintQueue objects.
public ref class PrintQueueCollection : System::Printing::PrintSystemObjects, IDisposable, System::Collections::Generic::IEnumerable<System::Printing::PrintQueue ^>
public class PrintQueueCollection : System.Printing.PrintSystemObjects, IDisposable, System.Collections.Generic.IEnumerable<System.Printing.PrintQueue>
type PrintQueueCollection = class
inherit PrintSystemObjects
interface seq<PrintQueue>
interface IEnumerable
interface IDisposable
Public Class PrintQueueCollection
Inherits PrintSystemObjects
Implements IDisposable, IEnumerable(Of PrintQueue)
- Inheritance
- Implements
Examples
The following example shows how to use this collection to test a printer's capabilities and configure a print job to take advantage of them.
// ---------------------- GetPrintTicketFromPrinter -----------------------
/// <summary>
/// Returns a PrintTicket based on the current default printer.</summary>
/// <returns>
/// A PrintTicket for the current local default printer.</returns>
PrintTicket^ GetPrintTicketFromPrinter ()
{
PrintQueue^ printQueue = nullptr;
LocalPrintServer^ localPrintServer = gcnew LocalPrintServer();
// Retrieving collection of local printer on user machine
PrintQueueCollection^ localPrinterCollection = localPrintServer->GetPrintQueues();
System::Collections::IEnumerator^ localPrinterEnumerator = localPrinterCollection->GetEnumerator();
if (localPrinterEnumerator->MoveNext())
{
// Get PrintQueue from first available printer
printQueue = ((PrintQueue^)localPrinterEnumerator->Current);
} else
{
return nullptr;
}
// Get default PrintTicket from printer
PrintTicket^ printTicket = printQueue->DefaultPrintTicket;
PrintCapabilities^ printCapabilities = printQueue->GetPrintCapabilities();
// Modify PrintTicket
if (printCapabilities->CollationCapability->Contains(Collation::Collated))
{
printTicket->Collation = Collation::Collated;
}
if (printCapabilities->DuplexingCapability->Contains(Duplexing::TwoSidedLongEdge))
{
printTicket->Duplexing = Duplexing::TwoSidedLongEdge;
}
if (printCapabilities->StaplingCapability->Contains(Stapling::StapleDualLeft))
{
printTicket->Stapling = Stapling::StapleDualLeft;
}
return printTicket;
};// end:GetPrintTicketFromPrinter()
// ---------------------- GetPrintTicketFromPrinter -----------------------
/// <summary>
/// Returns a PrintTicket based on the current default printer.</summary>
/// <returns>
/// A PrintTicket for the current local default printer.</returns>
private PrintTicket GetPrintTicketFromPrinter()
{
PrintQueue printQueue = null;
LocalPrintServer localPrintServer = new LocalPrintServer();
// Retrieving collection of local printer on user machine
PrintQueueCollection localPrinterCollection =
localPrintServer.GetPrintQueues();
System.Collections.IEnumerator localPrinterEnumerator =
localPrinterCollection.GetEnumerator();
if (localPrinterEnumerator.MoveNext())
{
// Get PrintQueue from first available printer
printQueue = (PrintQueue)localPrinterEnumerator.Current;
}
else
{
// No printer exist, return null PrintTicket
return null;
}
// Get default PrintTicket from printer
PrintTicket printTicket = printQueue.DefaultPrintTicket;
PrintCapabilities printCapabilities = printQueue.GetPrintCapabilities();
// Modify PrintTicket
if (printCapabilities.CollationCapability.Contains(Collation.Collated))
{
printTicket.Collation = Collation.Collated;
}
if ( printCapabilities.DuplexingCapability.Contains(
Duplexing.TwoSidedLongEdge) )
{
printTicket.Duplexing = Duplexing.TwoSidedLongEdge;
}
if (printCapabilities.StaplingCapability.Contains(Stapling.StapleDualLeft))
{
printTicket.Stapling = Stapling.StapleDualLeft;
}
return printTicket;
}// end:GetPrintTicketFromPrinter()
' ---------------------- GetPrintTicketFromPrinter -----------------------
''' <summary>
''' Returns a PrintTicket based on the current default printer.</summary>
''' <returns>
''' A PrintTicket for the current local default printer.</returns>
Private Function GetPrintTicketFromPrinter() As PrintTicket
Dim printQueue As PrintQueue = Nothing
Dim localPrintServer As New LocalPrintServer()
' Retrieving collection of local printer on user machine
Dim localPrinterCollection As PrintQueueCollection = localPrintServer.GetPrintQueues()
Dim localPrinterEnumerator As System.Collections.IEnumerator = localPrinterCollection.GetEnumerator()
If localPrinterEnumerator.MoveNext() Then
' Get PrintQueue from first available printer
printQueue = CType(localPrinterEnumerator.Current, PrintQueue)
Else
' No printer exist, return null PrintTicket
Return Nothing
End If
' Get default PrintTicket from printer
Dim printTicket As PrintTicket = printQueue.DefaultPrintTicket
Dim printCapabilities As PrintCapabilities = printQueue.GetPrintCapabilities()
' Modify PrintTicket
If printCapabilities.CollationCapability.Contains(Collation.Collated) Then
printTicket.Collation = Collation.Collated
End If
If printCapabilities.DuplexingCapability.Contains(Duplexing.TwoSidedLongEdge) Then
printTicket.Duplexing = Duplexing.TwoSidedLongEdge
End If
If printCapabilities.StaplingCapability.Contains(Stapling.StapleDualLeft) Then
printTicket.Stapling = Stapling.StapleDualLeft
End If
Return printTicket
End Function ' end:GetPrintTicketFromPrinter()
Remarks
Caution
Classes within the System.Printing namespace are not supported for use within a Windows service or ASP.NET application or service. Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions.
If you want to print from a Windows Forms application, see the System.Drawing.Printing namespace.
Constructors
| Name | Description |
|---|---|
| PrintQueueCollection() |
Initializes a new instance of the PrintQueueCollection class. |
| PrintQueueCollection(PrintServer, String[], EnumeratedPrintQueueTypes[]) |
Initializes a new instance of the PrintQueueCollection class for the specified PrintServer, containing only the print server's queues of the specified EnumeratedPrintQueueTypes. |
| PrintQueueCollection(PrintServer, String[]) |
Initializes a new instance of the PrintQueueCollection class for the specified PrintServer. |
Properties
| Name | Description |
|---|---|
| SyncRoot |
Gets an object that can be used to synchronize access to the PrintQueueCollection. |
Methods
| Name | Description |
|---|---|
| Add(PrintQueue) |
Adds a PrintQueue to the collection. |
| Dispose() |
Releases all resources used by the PrintSystemObjects. (Inherited from PrintSystemObjects) |
| Dispose(Boolean) |
Releases the unmanaged resources that are being used by the PrintQueueCollection, and optionally releases the managed resources that are being used. |
| GetEnumerator() |
Returns an object that implements the generic IEnumerator interface that has been closed with PrintQueue. |
| GetNonGenericEnumerator() |
Gets an object that implements the non-generic IEnumerator interface. |
Explicit Interface Implementations
| Name | Description |
|---|---|
| IEnumerable.GetEnumerator() |
Returns an object that implements the generic IEnumerator interface that has been closed with PrintQueue. |