|
1 |
| -<!-- default badges list --> |
2 |
| - |
3 |
| -[](https://supportcenter.devexpress.com/ticket/details/E1765) |
4 |
| -[](https://docs.devexpress.com/GeneralInformation/403183) |
5 |
| -[](#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://supportcenter.devexpress.com/ticket/details/E1765) |
| 3 | +[](https://docs.devexpress.com/GeneralInformation/403183) |
| 4 | +[](#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 | + |
| 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 --> |
35 | 82 | ## Does this example address your development requirements/objectives?
|
36 | 83 |
|
37 | 84 | [<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)
|
38 | 85 |
|
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 | + |
0 commit comments