Skip to content

Commit ce5e966

Browse files
Merge pull request #1 from DevExpress-Examples/ritazakhodyaeva-patch-1
Revise Readme for clarity and structure
2 parents d1faf53 + 26dab4d commit ce5e966

File tree

2 files changed

+86
-36
lines changed

2 files changed

+86
-36
lines changed

Readme.md

Lines changed: 86 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,90 @@
1-
<!-- default badges list -->
2-
![](https://img.shields.io/endpoint?url=https://codecentral.devexpress.com/api/v1/VersionRange/128602470/24.2.1%2B)
3-
[![](https://img.shields.io/badge/Open_in_DevExpress_Support_Center-FF7200?style=flat-square&logo=DevExpress&logoColor=white)](https://supportcenter.devexpress.com/ticket/details/E1765)
4-
[![](https://img.shields.io/badge/📖_How_to_use_DevExpress_Examples-e9f6fc?style=flat-square)](https://docs.devexpress.com/GeneralInformation/403183)
5-
[![](https://img.shields.io/badge/💬_Leave_Feedback-feecdd?style=flat-square)](#does-this-example-address-your-development-requirementsobjectives)
6-
<!-- default badges end -->
7-
# Reporting for WinForms - Print Multiple Reports in a Batch
8-
9-
In this example, the reports are printed in a single batch, instead of sending one report at a time to the printer. The **Print** dialog box is only called for the first report, the other reports are printed without prompting, with the same print settings.
10-
11-
12-
The [PrintTool.Printdialog](https://docs.devexpress.com/WindowsForms/DevExpress.XtraPrinting.PrintTool.PrintDialog.overloads) method is used to print the reports. The [StartPrint](https://docs.devexpress.com/CoreLibraries/DevExpress.XtraPrinting.PrintingSystemBase.StartPrint) event is handled to specify print settings.
13-
14-
15-
## Files to Review
16-
17-
* [Form1.cs](CS/BatchPrinting/Form1.cs) (VB: [Form1.vb](VB/BatchPrinting/Form1.vb))
18-
19-
## Documentation
20-
21-
- [Printing System](https://docs.devexpress.com/WindowsForms/10733/controls-and-libraries/printing-exporting/concepts/basic-terms/printing-system)
22-
- [Printing-Exporting](https://docs.devexpress.com/WindowsForms/2079/controls-and-libraries/printing-exporting)
23-
- [Print a Report](https://docs.devexpress.com/XtraReports/5191/winforms-reporting/winforms-reporting-print-api/print-a-report)
24-
25-
## More Examples
26-
27-
- [How to programmatically select a printe](https://github.com/DevExpress-Examples/Reporting_how-to-programmatically-select-a-printer-e1766)
28-
- [How to determine the settings of the selected printer when the OK button is pressed in the Printer dialog](https://github.com/DevExpress-Examples/Reporting_how-to-determine-the-settings-of-the-selected-printer-when-the-ok-button-is-pressed-e1767)
29-
- [How to dynamically select the paper source and set the printer resolution](https://github.com/DevExpress-Examples/Reporting_how-to-dynamically-select-the-paper-source-and-set-the-printer-resolution-e332)
30-
- [How to programmatically print a specified range of report pages](https://github.com/DevExpress-Examples/Reporting_how-to-programmatically-print-a-specified-range-of-report-pages-e1768)
31-
32-
33-
34-
<!-- feedback -->
1+
<!-- default badges list -->
2+
[![](https://img.shields.io/badge/Open_in_DevExpress_Support_Center-FF7200?style=flat-square&logo=DevExpress&logoColor=white)](https://supportcenter.devexpress.com/ticket/details/E1765)
3+
[![](https://img.shields.io/badge/📖_How_to_use_DevExpress_Examples-e9f6fc?style=flat-square)](https://docs.devexpress.com/GeneralInformation/403183)
4+
[![](https://img.shields.io/badge/💬_Leave_Feedback-feecdd?style=flat-square)](#does-this-example-address-your-development-requirementsobjectives)
5+
<!-- default badges end -->
6+
# Reporting for WinForms - Print Multiple Reports in a Batch
7+
8+
This example sends multiple reports to the printer. The Print dialog appears only once, before the first report is printed. This dialog specifies print settings for all reports.
9+
10+
![Print dialog](/images/print.png)
11+
12+
## Implementation Details
13+
14+
* Use the [PrintTool.PrintDialog](https://docs.devexpress.com/WindowsForms/DevExpress.XtraPrinting.PrintTool.PrintDialog.overloads) method for the first report to display the Print dialog and specify print settings.
15+
* Handle the [StartPrint](https://docs.devexpress.com/CoreLibraries/DevExpress.XtraPrinting.PrintingSystemBase.StartPrint) event to capture these settings and apply them to each report before printing.
16+
* Call the [Print](https://docs.devexpress.com/CoreLibraries/DevExpress.XtraPrinting.PrintToolBase.Print.overloads) method to print subsequent reports with the same printer settings, without prompting the user again.
17+
18+
```cs
19+
// Stores the printer settings selected by the user in the print dialog.
20+
private PrinterSettings prnSettings;
21+
22+
// Handles the button click event to start the batch printing process.
23+
private void button1_Click(object sender, EventArgs e) {
24+
XtraReport1 report1 = new XtraReport1();
25+
XtraReport[] reports = new XtraReport[] { new XtraReport2(), new XtraReport3() };
26+
27+
// Creates a print tool for the first report and subscribe to the StartPrint event.
28+
ReportPrintTool pt1 = new ReportPrintTool(report1);
29+
pt1.PrintingSystem.StartPrint += new PrintDocumentEventHandler(PrintingSystem_StartPrint);
30+
31+
// Subscribes to the StartPrint event for each additional report.
32+
foreach (XtraReport report in reports) {
33+
ReportPrintTool pts = new ReportPrintTool(report);
34+
pts.PrintingSystem.StartPrint += new PrintDocumentEventHandler(reportsStartPrintEventHandler);
35+
}
36+
37+
// Shows the print dialog for the first report.
38+
if(pt1.PrintDialog() == true) {
39+
// If the user confirms, print all additional reports with the selected printer settings
40+
foreach(XtraReport report in reports) {
41+
ReportPrintTool pts = new ReportPrintTool(report);
42+
pts.Print();
43+
}
44+
}
45+
}
46+
47+
// Event handler to capture the printer settings from the print dialog.
48+
void PrintingSystem_StartPrint(object sender, PrintDocumentEventArgs e) {
49+
prnSettings = e.PrintDocument.PrinterSettings;
50+
}
51+
52+
// Event handler to apply the captured printer settings to each report before printing.
53+
private void reportsStartPrintEventHandler(object sender, PrintDocumentEventArgs e) {
54+
int pageCount = e.PrintDocument.PrinterSettings.ToPage;
55+
e.PrintDocument.PrinterSettings = prnSettings;
56+
57+
// Ensures all pages are printed, even if reports have different page counts.
58+
e.PrintDocument.PrinterSettings.ToPage = pageCount;
59+
}
60+
```
61+
62+
63+
## Files to Review
64+
65+
* [Form1.cs](CS/BatchPrinting/Form1.cs) (VB: [Form1.vb](VB/BatchPrinting/Form1.vb))
66+
67+
## Documentation
68+
69+
- [Printing System](https://docs.devexpress.com/WindowsForms/10733/controls-and-libraries/printing-exporting/concepts/basic-terms/printing-system)
70+
- [Printing-Exporting](https://docs.devexpress.com/WindowsForms/2079/controls-and-libraries/printing-exporting)
71+
- [Print a Report](https://docs.devexpress.com/XtraReports/5191/winforms-reporting/winforms-reporting-print-api/print-a-report)
72+
- [Merge Reports](https://docs.devexpress.com/XtraReports/3320/detailed-guide-to-devexpress-reporting/merge-reports)
73+
74+
## More Examples
75+
76+
- [How to programmatically select a printe](https://github.com/DevExpress-Examples/Reporting_how-to-programmatically-select-a-printer-e1766)
77+
- [How to determine the settings of the selected printer when the OK button is pressed in the Printer dialog](https://github.com/DevExpress-Examples/Reporting_how-to-determine-the-settings-of-the-selected-printer-when-the-ok-button-is-pressed-e1767)
78+
- [How to dynamically select the paper source and set the printer resolution](https://github.com/DevExpress-Examples/Reporting_how-to-dynamically-select-the-paper-source-and-set-the-printer-resolution-e332)
79+
- [How to programmatically print a specified range of report pages](https://github.com/DevExpress-Examples/Reporting_how-to-programmatically-print-a-specified-range-of-report-pages-e1768)
80+
81+
<!-- feedback -->
3582
## Does this example address your development requirements/objectives?
3683

3784
[<img src="https://www.devexpress.com/support/examples/i/yes-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=reporting-winforms-print-reports-in-batch&~~~was_helpful=yes) [<img src="https://www.devexpress.com/support/examples/i/no-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=reporting-winforms-print-reports-in-batch&~~~was_helpful=no)
3885

39-
(you will be redirected to DevExpress.com to submit your response)
40-
<!-- feedback end -->
86+
(you will be redirected to DevExpress.com to submit your response)
87+
<!-- feedback end -->
88+
89+
90+

images/print.png

18.3 KB
Loading

0 commit comments

Comments
 (0)