PrintDialog 类


调用标准的 Microsoft Windows 打印对话框,此对话框可根据用户输入配置 PrintTicketPrintQueue,然后打印文档。Invokes a standard Microsoft Windows print dialog box that configures a PrintTicket and PrintQueue according to user input and then prints a document.

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


下面的示例演示如何使用 可扩展应用程序标记语言 (XAML)Extensible Application Markup Language (XAML) 标记和代码创建的实例,并显示简单的 PrintDialogThe following example shows how to create an instance of and display a simple PrintDialog by using 可扩展应用程序标记语言 (XAML)Extensible Application Markup Language (XAML) markup and code.

<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


用户可以使用 "打印" 对话框选择打印机,对其进行配置,然后执行打印作业。A user can use the Print dialog box to select a printer, configure it, and perform a print job.

严格地说,您可以使用 PrintDocument 方法,无需打开对话框。Strictly speaking, you can use the PrintDocument method without ever opening the dialog. 在这种意义上,控件可用作不可见的打印组件。In that sense, the control can be used as an unseen printing component. 但出于性能方面的原因,最好是使用 XpsDocumentWriterAddJob 方法或多个 WriteWriteAsync 方法中的一个。But for performance reasons, it would be better to use either the AddJob method or one of the many Write and WriteAsync methods of the XpsDocumentWriter. 有关详细信息,请参阅如何:以编程方式打印 XPS 文件For more about this, see How to: Programmatically Print XPS Files.

不要将此类与 System.Windows.Forms.PrintDialogSystem.Windows.Controls.PrintDialog混淆。Do not confuse this class, System.Windows.Controls.PrintDialog, with System.Windows.Forms.PrintDialog. 后者用于 Windows 窗体应用程序。The latter is used with Windows Forms applications. System.Windows.Controls.PrintDialog 用于 Windows Presentation Foundation 应用程序。System.Windows.Controls.PrintDialog is used with Windows Presentation Foundation applications.



初始化 PrintDialog 类的新实例。Initializes a new instance of the PrintDialog class.



获取或设置一个值,该指示打印当前页的选项是否可用。Gets or sets a value that indicates whether the option to print the current page is enabled.


获取或设置页范围内允许的最大页码。Gets or sets the highest page number that is allowed in page ranges.


获取或设置页范围内允许的最小页码。Gets or sets the lowest page number that is allowed in page ranges.


获取或设置在 PageRangeSelection 设置为 UserPages 时要打印的页范围。Gets or sets the range of pages to print when PageRangeSelection is set to UserPages.


获取或设置此 PageRangeSelection 实例的 PrintDialogGets or sets the PageRangeSelection for this instance of PrintDialog.


获取页面的可打印区域的高度。Gets the height of the printable area of the page.


获取页面的可打印区域的宽度。Gets the width of the printable area of the page.


获取或设置一个表示选定的打印机的 PrintQueueGets or sets a PrintQueue that represents the printer that is selected.


获取或设置当用户针对当前打印作业单击“打印”时 PrintTicket 使用的 PrintDialogGets or sets the PrintTicket that is used by the PrintDialog when the user clicks Print for the current print job.


获取或设置指示是否启用打印所选页的选项的值。Gets or sets a value that indicates whether the option to print the selected pages is enabled.


获取或设置一个值,该值指示“打印”对话框的用户是否可以使用一个选项指定要打印的页范围。Gets or sets a value that indicates whether users of the Print dialog box have the option to specify ranges of pages to print.



确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
PrintDocument(DocumentPaginator, String)

DocumentPaginator 对象打印到当前选定的 PrintQueuePrints a DocumentPaginator object to the PrintQueue that is currently selected.

PrintVisual(Visual, String)

将派生自 Visual 类的可见(非文本)对象打印到当前选定的 PrintQueuePrints a visual (non-text) object, which is derived from the Visual class, to the PrintQueue that is currently selected.


调用 PrintDialog 为模式对话框。Invokes the PrintDialog as a modal dialog box.


返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)