PrintDialog 类

定义

调用一个标准Microsoft Windows 打印对话框,该对话框配置并PrintQueue按用户输入配置PrintTicket,然后打印文档。

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

示例

以下示例演示如何使用可扩展应用程序标记语言(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.Value)
    {
        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该方法或方法之XpsDocumentWriter一和WriteAsync方法之一Write。 有关此内容的详细信息,请参阅 如何:以编程方式打印 XPS 文件

不要将此类 System.Windows.Controls.PrintDialogSystem.Windows.Forms.PrintDialog.. 后者与 Windows 窗体应用程序一起使用。 System.Windows.Controls.PrintDialog 与 Windows Presentation Foundation 应用程序一起使用。

构造函数

名称 说明
PrintDialog()

初始化 PrintDialog 类的新实例。

属性

名称 说明
CurrentPageEnabled

获取或设置一个值,该值指示是否启用打印当前页的选项。

MaxPage

获取或设置页范围中允许的最高页码。

MinPage

获取或设置页范围中允许的最低页码。

PageRange

获取或设置在设置为 要打印的页面范围。

PageRangeSelection

获取或设置 PageRangeSelection 此实例的 PrintDialog此实例。

PrintableAreaHeight

获取页面的可打印区域的高度。

PrintableAreaWidth

获取页面的可打印区域的宽度。

PrintQueue

获取或设置一个 PrintQueue 表示所选打印机的打印机。

PrintTicket

获取或设置PrintTicket用户单击当前打印作业的“打印”时所使用的PrintDialog值。

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)

适用于