Set Up to Print

To set up to print the report, you must:

You can create an XML printer configuration file for many types of printers. A sample configuration file that will work with most report printers is included with the sample application.

LinePrinter Constructor

The LinePrinter constructors are defined as:   

public LinePrinter(string Printer)
public LinePrinter(string FileName, string Printer)

The first constructor uses ITC_CONFIG.XML and lets you specify which printer to choose in that file.  Printer refers to an entry in ITC_CONFIG.XML that describes the printer you want to choose and tells LinePrinter how to operate it.

The second constructor lets you specify an XML printer configuration file and which printer to choose in that file. FileName is the name and location of your printer configuration file and Printer refers to an entry in the file that describes the printer you want to choose. If FileName is omitted, then ITC_CONFIG.XML is used as the configuration file name.

The static method EnumeratePrinters may be used to help display a list of printers supported by the configuration file. Please see the LinePrinter reference and Sample Application for information regarding this function.

Example:

public LinePrinter lp;
.
. .
lp = new LinePrinter(temp,"Printer6820NPCP");

Printer Configuration File

The printer configuration file is an XML file that contains information about printers that might be used within an application and the port through which that printer is connected to the computer.

Setting Event Handling Through Delegates

During the course of printing the report, there are several events that may be fired to inform the application of the status or of a required action. These static events are communicated to the application through delegates that may be added at any time. These delegates are described next.

HeaderEventHandler Delegate

This event is fired at the top of each new page of a report.

lp.HeaderEventEx += new LinePrinter.HeaderEventHandler(PrintHeader);

FooterEventHandler Delegate

This event is fired before the end of each page. The LinePrinter class automatically computes the number of lines needed for the footer before the report starts printing, and will fire this event when there are just enough lines left on a page to include the footer. The LinePrinter class computes the number of lines needed by actually firing the FooterEventEx once before the report has started printing while discarding the output without printing. For this reason, ongoing calculations should not take place in the footer function.

lp.FooterEventEx += new LinePrinter.FooterEventHandler(PrintFooter);

StatusMessageEventHandler Delegate

There are several status types that may be sent through the firing of the StatusMessageEvent. They are an indication of the print job status that may be used to trigger updates to an update screen in the application.

lp.StatusMessageEventHandlerEx += new LinePrinter.StatusMessageEventHandler(MyPrintMessage);

WarningMessageEventHandler Delegate

lp.WarningMessageEventEx += new LinePrinter.WarningMessageEventHandler(WarningHandler);

A sample WarningMessageEvent handler function would have this form:

public void WarningHandler(object source, LinePrinter.WarningMessageArgs Error)
{
    string temp;
    DialogResult result;
    temp = string.Format("{0} from {1} Printer \n\r\n\r Fix problem and continue
         printing?",NPCPErrorStr(Error.ErrorCode),Error.DeviceType);
    result = MessageBox.Show(temp, "PRINTER WARNING", MessageBoxButtons.YesNo,
        MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
    if (result == DialogResult.No) lp.Cancel();
}

Creating the Connection with the Open Method

This method creates the connection to the printer. LinePrinter will not look for the printer configuration file until you call Open. The syntax of the Open method is:

public void Open();

Example:

lp.Open();

More Information

Next » Print Routine: Generate a Report

Back « Print Routine Overview