WPF报告打印
本文关键字:打印 报告 WPF | 更新日期: 2023-09-27 18:22:23
我正在使用C#和WPF生成一个水晶报告。
到目前为止,我的代码是
report.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)System.Drawing.Printing.PaperKind.A5;
report.PrintToPrinter(2, true, 0, 0);
crystalReportsViewer1.ViewerCore.ReportSource = report;
crystalReportsViewer1.ToggleSidePanel = SAPBusinessObjects.WPF.Viewer.Constants.SidePanelKind.None;
我需要显示一个对话框,即PrintDialog,允许用户只选择他想要打印的打印机,其余的打印设置由我在代码中完成。请建议。。。。
尝试以下代码
PrintDialog printDialog1 = new PrintDialog();
if (printDialog1.ShowDialog() == true)
{
report.PrintOptions.PrinterName = printDialog1.PrintQueue.Name;
report.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)System.Drawing.Printing.PaperKind.A5;
report.PrintToPrinter(2, true, 0, 0);
crystalReportsViewer1.ViewerCore.ReportSource = report;
crystalReportsViewer1.ToggleSidePanel = SAPBusinessObjects.WPF.Viewer.Constants.SidePanelKind.None;
}
System.Printing必须在您的引用中,这样您才能使用PrintQueue.Name.