c# - 在 WPF 中使用 System.Drawing.Printing.PrintDocument

标签 c# wpf printing

我有一个 WPF 应用程序,我使用外部库生成文档。该库将文档作为 System.Drawing.Printing.PrintDocument 返回。如何在 WPF 中打印此文档?我可以直接使用 Print() 方法,但我需要允许用户选择打印机和设置。如果我使用 WPF PrintDocument 对话框,我不能像在 WinForms dialog.Document 中那样将我的文档设置到它。有没有办法将旧的 PrintDocument 转换为某种 WPF 友好形式?

WinForms 方式:

// get document for printing
PrintDocument document = exporter.GetPrintDocument();
System.Windows.Forms.PrintDialog dialog = new System.Windows.Forms.PrintDialog();
dialog.Document = document;
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
    document.Print();
}

WPF方式:

System.Windows.Controls.PrintDialog dialog = new System.Windows.Controls.PrintDialog();
if (dialog.ShowDialog() == true)
{
    // how to print old PrintDocument???
    dialog.PrintDocument(...);
}

我还尝试在 WPF 中打开 WinForms 对话框,但这是不可能的。只是没有显示对话框。

感谢您的帮助。

最佳答案

我找到了答案。您必须将 UseDialogEx 对话框属性设置为 true

关于c# - 在 WPF 中使用 System.Drawing.Printing.PrintDocument,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1657737/

相关文章:

Javascript:Window.print() 之后的空 html div 内容

printing - Notepad++彩色打印或替代品

c# - 在 .NET 中创建自定义打印端口

c# - ASP.NET Web APi - 将对象作为参数传递

C# 删除空白单元格

c# - visual studio Express 2013 是否自带 blend,如何打开它?

c# - 如何在两个线程之间正确传递包含资源的 UserControl?

c# - 在 ZedGraph 中是否可以使用不同颜色填充曲线项?

C#:在浏览器中呈现的像素宽度匹配文本

wpf datagrid 数据绑定(bind)与嵌套对象(如主细节)