Implement Printing and Reporting Functionality in a Windows Forms Application
These questions are based on 70-526VB: TS: Microsoft .NET Framework 2.0 – Windows-Based Client Development (VB.NET)
Microsoft
Self Test Software Practice Test
Objective: Implement Printing and Reporting Functionality in a Windows Forms application.
Sub-objective: Construct print documents.
Single answer, multiple-choice
You are an application developer in a company. You create an application using Visual Basic .NET. The application enables end users to print legal forms. You need to ensure that 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.vb.
Which code should you insert into your application to show the message box on the completion of the document printing job?
- Private Sub PrintDocument1_EndPrint(ByVal sender As Object, _
ByVal e As System.Drawing.Printing.PrintEventArgs) Handles _
PrintDocument1.EndPrint
MessageBox.Show(“Finished printing”)
End Sub - Private Sub PrintDocument1_BeginPrint(ByVal sender As Object, _
ByVal e As System.Drawing.Printing.PrintEventArgs) Handles _
PrintDocument1.BeginPrint
MessageBox.Show(“Finished printing”)
End Sub - Private Sub PrintDocument1_QueryPageSettings(ByVal sender As _
Object, ByVal e As System.Drawing.Printing.QueryPageSettingsEventArgs) _
Handles PrintDocument1.QueryPageSettings
MessageBox.Show(“Finished printing”)
End Sub - Private Sub PrintDocument1_PrintPage(ByVal sender As Object, _
ByVal e As System.Drawing.Printing.PrintEventArgs) Handles _
PrintDocument1.PrintPage
MessageBox.Show(“Finished printing”)
End Sub
Answer:
A. Private Sub PrintDocument1_EndPrint(ByVal sender As Object, _
ByVal e As System.Drawing.Printing.PrintEventArgs) Handles _
PrintDocument1.EndPrint
MessageBox.Show(“Finished printing”)
End Sub
Tutorial:
You should use the following code:
Private Sub PrintDocument1_EndPrint(ByVal sender As Object, _
ByVal e As System.Drawing.Printing.PrintEventArgs) Handles _
PrintDocument1.EndPrint
MessageBox.Show(“Finished printing”)
End Sub
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.