要实现该功能,首先需使用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