/
Form1.cs
50 lines (40 loc) · 1.76 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Windows.Forms;
using System.Drawing.Printing;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
// ...
namespace BatchPrinting {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private PrinterSettings prnSettings;
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);
}
if(pt1.PrintDialog() == true) {
foreach(XtraReport report in reports) {
ReportPrintTool pts = new ReportPrintTool(report);
pts.Print();
}
}
}
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;
// Do this if your reports contain different number of pages,
// and you always need to print all pages in a report.
e.PrintDocument.PrinterSettings.ToPage = pageCount;
}
}
}