What is the result of the following code? Assume that objOutput_PrintPage is defined.
private void btnPrint_Click(
object sender, System.EventArgs e )
{
PrintDocument objOutput = new PrintDocument();
// add PrintPage event handler
objOutput.PrintPage += new PrintPageEventHandler(
objOutput_PrintPage );
objOutput.Print();
} // end method btnPrint_Click
The code indicates that the PrintPage event for objOutput should invoke the
objOutput_PrintPage event handler. The complete code reads:
// PrintDocument.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Printing;
namespace PrntDocument
{
///
/// Summary description for FrmPrintDocument.
///
public class FrmPrintDocument : System.Windows.Forms.Form
{
private System.Windows.Forms.Label lblinput;
private System.Windows.Forms.TextBox txtInput;
private System.Windows.Forms.Button btnPrint;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public FrmPrintDocument()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent
// call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
// Windows Form Designer generated code
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run( new FrmPrintDocument() );
}
// defines an event handler for the PrintPage event
private void btnPrint_Click(
object sender, System.EventArgs e )
{
PrintDocument objOutput = new PrintDocument();
// add PrintPage event handler
objOutput.PrintPage += new PrintPageEventHandler(
objOutput_PrintPage );
objOutput.Print();
} // end method btnPrint_Click
// prints an empty page
private void objOutput_PrintPage( object sender,
System.Drawing.Printing.PrintPageEventArgs e )
{
// if no printers installed, display error message
if ( PrinterSettings.InstalledPrinters.Count == 0 )
{
MessageBox.Show( "Printer Unavailable", "Error",
MessageBoxButtons.RetryCancel,
MessageBoxIcon.Error );
return; // exit event handler
}
} // end method objOutput_PrintPage
} // end class FrmPrintDocument
}

You might also like to view...
Which of the following is not a major area of deadlock research?
a) prevention b) avoidance c) recovery d) none of the above
A(n) _________ is inserted to divide a document into multiple sections.? A. section window B. section tag C. section break D. section title
Fill in the blank(s) with the appropriate word(s).
Some advanced switches have this ability to mirror data from any or all physical ports to a single physical port in order to monitor traffic.
A. port blocking B. port mirroring C. load balancing D. port authentication
________ rights may be used to prevent others from using a confusingly similar mark, but not to prevent others from making the same goods or from selling the same goods or services under a clearly different mark.
Fill in the blank(s) with the appropriate word(s).