The PrintToPrinter() method needs to be explained in more detail because the parameters passed to this method aren’t intuitive. The parameters of the PrintToPrinter() method are listed in Table 3-1.
Table 3-1. PrintToPrinter() parameters.
Parameter | Description |
---|---|
nCopies | The number of copies to print. |
Collated | Set to True to collate the pages. |
startPageN | The first page to print. Set to 0 to print all pages. |
endPageN | The last page to print. Set to 0 to print all pages. |
The first parameter, nCopies, sets how many copies of the report to print. If more than one copy of the report is being printed, the second property tells whether to collate the copies or not. Passing False tells it to print each full report prior to printing the next copy. If nCopies is set to 1, then the collated parameter is ignored. The last two parameters, startPageN and endPageN, set the page range. Pass it the first page to print and the last page to print. To print the entire report, pass 0 to both parameters.
When using the viewer control, you also have the option of using a ReportDocument component (see the example in Chapter 1). The ReportDocument component gives you a visual way of telling the viewer which report you want to print. If you are writing a Windows application, adding the ReportDocument component lets you preview a report without writing any code whatsoever. The ReportDocument component also gives you the benefit of being in design mode and letting you see the name of the report that is going to be printed without having to read the programming code.
At this point in the chapter, you’ve had the chance to examine when you should use the viewer or when to send reports directly to the printer. If you use the viewer control, you have the option to add a ReportDocument component. The next major decision to make is how you want to instantiate the report object.
.NET applications are fully object oriented and thus everything is considered an object. Reports are no different. Crystal Reports .NET uses the ReportDocument class to manage all report functionality. Before a report can be printed, you must instantiate a new ReportDocument object variable and load the report into it. The steps for instantiating the object and loading the report are dependent on the report type and classification. A report can be classified as either Strongly-Typed or Untyped.