Implementing printing and reporting functionality in a Windows Forms Application
By —
Questions derived from the 70-526CSHP - TS: Microsoft .NET Framework 2.0 - Windows-Based Client Development (C# .NET) Microsoft Self-Test Software Practice Test.
Objective: Implementing printing and reporting functionality in a Windows Forms Application
SubObjective: Construct print documents
Item Number: 70-526CSHP.3.2.11
Single Answer, Multiple Choice
You are an application developer in a company. You create an application using Visual C# .NET. The application enables end-users to print legal forms. You need to ensure each time a form is printed the end-user gets a message displayed on the screen giving information regarding the completion of the print job. You have a PrintDocument component named PrintDocument1 placed on the Windows form named Print.cs.
Which code should you insert into your application to show the message box on the completion of the document printing job?
- private void PrintDocument1_EndPrint ( object sender, PrintEventArgs e ) {
MessageBox.Show( "Finished printing" );
} - private void PrintDocument1_BeginPrint ( object sender, PrintEventArgs e ) {
MessageBox.Show( "Finished printing" );
} - private void PrintDocument1_QueryPageSettings ( object sender, PrintEventArgs e ) {
MessageBox.Show( "Finished printing" );
} - private void PrintDocument1_PrintPage ( object sender, PrintEventArgs e ) {
MessageBox.Show( "Finished printing" );
}
Answer:
A. private void PrintDocument1_EndPrint ( object sender, PrintEventArgs e ) {
MessageBox.Show( "Finished printing" );
}
Tutorial:
You should use the following code:
private void PrintDocument1_EndPrint ( object sender, PrintEventArgs e ) {
MessageBox.Show( "Finished printing" );
}
This code uses the EndPrint event of the PrintDocument1 component. This event occurs when the last page of the document has printed. If you show the message box in this event, the Finished Printing message will appear when the document has finished printing.
You should not use the code that uses the BeginPrint event. This event occurs before the first page of the document prints. Instead of displaying the message box at the end of the printing, this event will display the message at the starting of the printing job.
You should not use the code that uses the QueryPageSettings event. This event occurs immediately before each PrintPage event. This event enables you to add different page setting for each page in a document. You can modify individual properties of the page by using this event. If you place the message box in this event, it will display the Finished Printing message before printing each page.
You should not use the code that uses the PrintPage event. This event occurs before printing the output the current page. In this scenario, you need to display the message box with the Finished Printing message at the end of the printing job. Using this event, the message box will be displayed each time a page is printed.
MSDN Library > .NET Development > .NET Framework SDK > Class Library Reference > System.Drawing.Printing > PrintDocument Class > PrintDocument Events > EndPrint Event



