PrintTicket Constructors
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Initialiseert een nieuw exemplaar van de PrintTicket klasse.
Overloads
| Name | Description |
|---|---|
| PrintTicket() |
Initialiseert een nieuw exemplaar van de PrintTicket klasse. |
| PrintTicket(Stream) |
Initialiseert een nieuw exemplaar van de PrintTicket klasse met behulp van een XML-stroom (die een PrintTicket-document bevat) die voldoet aan het XML-afdrukschema. |
PrintTicket()
Initialiseert een nieuw exemplaar van de PrintTicket klasse.
public:
PrintTicket();
public PrintTicket();
Public Sub New ()
Voorbeelden
In het volgende voorbeeld ziet u hoe u deze constructor gebruikt bij het samenvoegen van twee afdruktickets.
/// <summary>
/// Changes the user-default PrintTicket setting of the specified print queue.
/// </summary>
/// <param name="queue">the printer whose user-default PrintTicket setting needs to be changed</param>
static private void ChangePrintTicketSetting(PrintQueue queue)
{
//
// Obtain the printer's PrintCapabilities so we can determine whether or not
// duplexing printing is supported by the printer.
//
PrintCapabilities printcap = queue.GetPrintCapabilities();
//
// The printer's duplexing capability is returned as a read-only collection of duplexing options
// that can be supported by the printer. If the collection returned contains the duplexing
// option we want to set, it means the duplexing option we want to set is supported by the printer,
// so we can make the user-default PrintTicket setting change.
//
if (printcap.DuplexingCapability.Contains(Duplexing.TwoSidedLongEdge))
{
//
// To change the user-default PrintTicket, we can first create a delta PrintTicket with
// the new duplexing setting.
//
PrintTicket deltaTicket = new PrintTicket();
deltaTicket.Duplexing = Duplexing.TwoSidedLongEdge;
//
// Then merge the delta PrintTicket onto the printer's current user-default PrintTicket,
// and validate the merged PrintTicket to get the new PrintTicket we want to set as the
// printer's new user-default PrintTicket.
//
ValidationResult result = queue.MergeAndValidatePrintTicket(queue.UserPrintTicket, deltaTicket);
//
// The duplexing option we want to set could be constrained by other PrintTicket settings
// or device settings. We can check the validated merged PrintTicket to see whether the
// the validation process has kept the duplexing option we want to set unchanged.
//
if (result.ValidatedPrintTicket.Duplexing == Duplexing.TwoSidedLongEdge)
{
//
// Set the printer's user-default PrintTicket and commit the set operation.
//
queue.UserPrintTicket = result.ValidatedPrintTicket;
queue.Commit();
Console.WriteLine("PrintTicket new duplexing setting is set on '{0}'.", queue.FullName);
}
else
{
//
// The duplexing option we want to set has been changed by the validation process
// when it was resolving setting constraints.
//
Console.WriteLine("PrintTicket new duplexing setting is constrained on '{0}'.", queue.FullName);
}
}
else
{
//
// If the printer doesn't support the duplexing option we want to set, skip it.
//
Console.WriteLine("PrintTicket new duplexing setting is not supported on '{0}'.", queue.FullName);
}
}
''' <summary>
''' Changes the user-default PrintTicket setting of the specified print queue.
''' </summary>
''' <param name="queue">the printer whose user-default PrintTicket setting needs to be changed</param>
Private Shared Sub ChangePrintTicketSetting(ByVal queue As PrintQueue)
'
' Obtain the printer's PrintCapabilities so we can determine whether or not
' duplexing printing is supported by the printer.
'
Dim printcap As PrintCapabilities = queue.GetPrintCapabilities()
'
' The printer's duplexing capability is returned as a read-only collection of duplexing options
' that can be supported by the printer. If the collection returned contains the duplexing
' option we want to set, it means the duplexing option we want to set is supported by the printer,
' so we can make the user-default PrintTicket setting change.
'
If printcap.DuplexingCapability.Contains(Duplexing.TwoSidedLongEdge) Then
'
' To change the user-default PrintTicket, we can first create a delta PrintTicket with
' the new duplexing setting.
'
Dim deltaTicket As New PrintTicket()
deltaTicket.Duplexing = Duplexing.TwoSidedLongEdge
'
' Then merge the delta PrintTicket onto the printer's current user-default PrintTicket,
' and validate the merged PrintTicket to get the new PrintTicket we want to set as the
' printer's new user-default PrintTicket.
'
Dim result As ValidationResult = queue.MergeAndValidatePrintTicket(queue.UserPrintTicket, deltaTicket)
'
' The duplexing option we want to set could be constrained by other PrintTicket settings
' or device settings. We can check the validated merged PrintTicket to see whether the
' the validation process has kept the duplexing option we want to set unchanged.
'
If result.ValidatedPrintTicket.Duplexing = Duplexing.TwoSidedLongEdge Then
'
' Set the printer's user-default PrintTicket and commit the set operation.
'
queue.UserPrintTicket = result.ValidatedPrintTicket
queue.Commit()
Console.WriteLine("PrintTicket new duplexing setting is set on '{0}'.", queue.FullName)
Else
'
' The duplexing option we want to set has been changed by the validation process
' when it was resolving setting constraints.
'
Console.WriteLine("PrintTicket new duplexing setting is constrained on '{0}'.", queue.FullName)
End If
Else
'
' If the printer doesn't support the duplexing option we want to set, skip it.
'
Console.WriteLine("PrintTicket new duplexing setting is not supported on '{0}'.", queue.FullName)
End If
End Sub
Van toepassing op
PrintTicket(Stream)
Initialiseert een nieuw exemplaar van de PrintTicket klasse met behulp van een XML-stroom (die een PrintTicket-document bevat) die voldoet aan het XML-afdrukschema.
public:
PrintTicket(System::IO::Stream ^ xmlStream);
public PrintTicket(System.IO.Stream xmlStream);
new System.Printing.PrintTicket : System.IO.Stream -> System.Printing.PrintTicket
Public Sub New (xmlStream As Stream)
Parameters
- xmlStream
- Stream
Een XML-stroom die een afdruktaak beschrijft en voldoet aan het afdrukschema.
Uitzonderingen
xmlStream is null.
xmlStream is ongeldige XML.
Opmerkingen
De constructor stelt de lees-/schrijfpositie van de stroom niet terug naar de oorspronkelijke positie. Daarom moet u deze onmiddellijk opnieuw instellen nadat u de constructor hebt aangeroepen.
Het hele PrintTicket-document wordt opgeslagen in een niet-openbaar veld in het object, inclusief de XML-elementen erin die minder algemene functies uitdrukken die niet worden vertegenwoordigd door een van de openbare eigenschappen van de PrintTicket klasse. Als het stuurprogramma dat het PrintTicket-document heeft geproduceerd, een persoonlijke uitbreiding van het afdrukschema gebruikt, wordt die persoonlijk gedefinieerde markering ook opgeslagen als onderdeel van het niet-openbare PrintTicket-document.
De privéonderdelen van het document, indien aanwezig, worden niet gevalideerd door de constructor, maar alle door het afdrukschema gedefinieerde onderdelen worden gevalideerd, inclusief de onderdelen die niet worden vertegenwoordigd door een van de openbare eigenschappen van de PrintTicket klasse. Daarom kan het FormatException worden gegenereerd, zelfs als alle XML-markeringen die overeenkomen met de openbare eigenschappen geldig zijn.
Wanneer een van de eigenschappen van de PrintTicket documenten naar wordt geschreven, wordt dit niet-openbare PrintTicket-document ook gewijzigd.
Het is dit niet-openbare PrintTicket-document dat wordt geretourneerd door de GetXmlStream en SaveTo methoden.