PrintTicket 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 PrintTicket 類別的新執行個體。
多載
| 名稱 | Description |
|---|---|
| PrintTicket() |
初始化 PrintTicket 類別的新執行個體。 |
| PrintTicket(Stream) |
透過使用 XML 串流(包含 PrintTicket 文件)初始化該類別的新實例 PrintTicket ,該串流符合 XML 列印結構。 |
PrintTicket()
初始化 PrintTicket 類別的新執行個體。
public:
PrintTicket();
public PrintTicket();
Public Sub New ()
範例
以下範例展示了合併兩張印刷票時如何使用此建構器。
/// <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
適用於
PrintTicket(Stream)
透過使用 XML 串流(包含 PrintTicket 文件)初始化該類別的新實例 PrintTicket ,該串流符合 XML 列印結構。
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)
參數
- xmlStream
- Stream
一個描述列印工作並符合列印結構的 XML 串流。
例外狀況
xmlStream 是 null。
xmlStream 不具效的 XML。
備註
建構子不會將串流的讀寫位置重置回原始位置。 因此,你應該在呼叫建構者後立即重置它。
整個 PrintTicket 文件會儲存在物件的非公開欄位中,包括其中表達較少見特徵的 XML 元素,這些特徵並未被類別的任何公開屬性 PrintTicket 所代表。 事實上,如果產生 PrintTicket 文件的驅動程式使用了 Print Schema 的私人擴充,該私有定義的標記也會作為非公開 PrintTicket 文件的一部分儲存。
文件中的私有部分(如有)不會被建構子驗證,但所有由 Print Schema 定義的部分都會被驗證,包括未被類別任何公開屬性 PrintTicket 表示的部分。 因此,即使所有與公開屬性對應的 XML 標記都有效,也可能會拋出 。FormatException
當寫入 的 PrintTicket 任意屬性時,這份非公開的 PrintTicket 文件也會被更改。
這份非公開的 PrintTicket 文件會由 GetXmlStream 和 SaveTo 方法 回傳。