PrintDialog 類別

定義

叫用根據使用者輸入設定 PrintTicketPrintQueue 的標準 Microsoft Windows 列印對話方塊,然後列印文件。

public ref class PrintDialog
public class PrintDialog
type PrintDialog = class
Public Class PrintDialog
繼承
PrintDialog

範例

下列範例示範如何使用 Extensible Application Markup Language (XAML) 標記和程式碼,建立 實例並顯示簡單 PrintDialog

<Button Width="200" Click="InvokePrint">Invoke PrintDialog</Button>

...

private void InvokePrint(object sender, RoutedEventArgs e)
    {
        // Create the print dialog object and set options
        PrintDialog pDialog = new PrintDialog();
        pDialog.PageRangeSelection = PageRangeSelection.AllPages;
        pDialog.UserPageRangeEnabled = true;

        // Display the dialog. This returns true if the user presses the Print button.
        Nullable<Boolean> print = pDialog.ShowDialog();
        if (print == true)
        {
            XpsDocument xpsDocument = new XpsDocument("C:\\FixedDocumentSequence.xps", FileAccess.ReadWrite);
            FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence();
            pDialog.PrintDocument(fixedDocSeq.DocumentPaginator, "Test print job");
        }
    }
Private Sub InvokePrint(ByVal sender As Object, ByVal e As RoutedEventArgs)
        ' Create the print dialog object and set options
        Dim pDialog As New PrintDialog()
        pDialog.PageRangeSelection = PageRangeSelection.AllPages
        pDialog.UserPageRangeEnabled = True

        ' Display the dialog. This returns true if the user presses the Print button.
        Dim print? As Boolean = pDialog.ShowDialog()
        If print = True Then
            Dim xpsDocument As New XpsDocument("C:\FixedDocumentSequence.xps", FileAccess.ReadWrite)
            Dim fixedDocSeq As FixedDocumentSequence = xpsDocument.GetFixedDocumentSequence()
            pDialog.PrintDocument(fixedDocSeq.DocumentPaginator, "Test print job")
        End If
End Sub

備註

使用者可以使用 [ 列印 ] 對話方塊來選取印表機、設定印表機,以及執行列印工作。

嚴格來說,您可以使用 PrintDocument 方法,而不需要開啟對話方塊。 如此一來,控制項就可以當做看不到的列印元件使用。 但基於效能考慮,最好是使用 AddJob 方法或 其中 Write 一個 和 WriteAsync 方法 XpsDocumentWriter 。 如需詳細資訊,請參閱 如何:以程式設計方式列印 XPS 檔案

請勿將這個類別 System.Windows.Controls.PrintDialogSystem.Windows.Forms.PrintDialog 混淆。 後者會與Windows Forms應用程式搭配使用。 System.Windows.Controls.PrintDialog會與Windows Presentation Foundation應用程式搭配使用。

建構函式

PrintDialog()

初始化 PrintDialog 類別的新執行個體。

屬性

CurrentPageEnabled

取得或設定值,指出列印目前頁面的選項是否已啟用。

MaxPage

取得或設定頁面範圍所允許之最大頁碼。

MinPage

取得或設定頁面範圍所允許之最小頁碼。

PageRange

取得或設定當 PageRangeSelection 設為 UserPages 時要列印的頁面範圍。

PageRangeSelection

取得或設定這個 PageRangeSelection 執行個體的 PrintDialog

PrintableAreaHeight

取得頁面可列印區域高度。

PrintableAreaWidth

取得頁面可列印區域寬度。

PrintQueue

取得或設定表示所選取之印表機的 PrintQueue

PrintTicket

取得或設定當使用者為目前列印工作按下 [列印] 時,PrintDialog 使用的 PrintTicket

SelectedPagesEnabled

取得或設定值,這個值表示列印所選頁面的選項是否已啟用。

UserPageRangeEnabled

取得或設定值,這個值表示 [列印] 對話方塊使用者是否可使用選項指定要列印之頁面範圍。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
PrintDocument(DocumentPaginator, String)

列印 DocumentPaginator 物件至目前選取的 PrintQueue

PrintVisual(Visual, String)

將從 Visual 類別衍生而來的視覺 (非文字) 物件列印到目前選取的 PrintQueue

ShowDialog()

叫用 PrintDialog 作為強制回應對話方塊。

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於