2024年终活动

DevExpress控件使用交流,DevExpress中国社区Dev联系电话 联系电话:023-68661681

如何同时打印多个DevExpress报表文件?

来源:本站   发布时间:2012-03-01   浏览:3895次

要实现该功能,首先需使用XtraReport.PrintDialog和XtraReport.Print方法打印报表,然后还需处理报表的XtraReport.PrintingSystem的PrintingSystemBase.StartPrint事件。

关键代码:

private void button1_Click(object sender, EventArgs e) {

            XtraReport1 report1 = new XtraReport1();

            XtraReport[] reports = new XtraReport[] { new XtraReport2(), new XtraReport3() };

 

            ReportPrintTool pt1 = new ReportPrintTool(report1);

            pt1.PrintingSystem.StartPrint += new PrintDocumentEventHandler(PrintingSystem_StartPrint);

 

            foreach (XtraReport report in reports) {

                ReportPrintTool pts = new ReportPrintTool(report);

                pts.PrintingSystem.StartPrint += new PrintDocumentEventHandler(reportsStartPrintEventHandler);

            }

                //打印报表

            pt1.PrintDialog();

            foreach (XtraReport report in reports) {

                ReportPrintTool pts = new ReportPrintTool(report);

                pts.Print();

            }

        }

              //处理StartPrint事件

        void PrintingSystem_StartPrint(object sender, PrintDocumentEventArgs e) {

            prnSettings = e.PrintDocument.PrinterSettings;

        }

 

        private void reportsStartPrintEventHandler(object sender, PrintDocumentEventArgs e) {

            int pageCount = e.PrintDocument.PrinterSettings.ToPage;

            e.PrintDocument.PrinterSettings = prnSettings;

 

            //如果报表包含不同的页数,并且您需要打印所有页,请执行该步骤

            e.PrintDocument.PrinterSettings.ToPage = pageCount;

        }

点击下载示例

本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/141.html
扫码咨询
电话咨询
023-68661681
返回
顶部