Posted by: Cirilo Meggiolaro | 10/20/2008

Tip of the day #6 – Windows Forms Printing Events

Print a custom document with .NET is quite simple and straightforward.

The start point to print is to create a PrintDocument object, add event handlers that fit your application needs and invoke the method Print().

The following event handlers are available for the PrintDocument object:

1. BeginPrint
The BeginPrint event is raised just once and before the first page prints.
Use the event to preset print level properties.

2. EndPrint
The EndPrint event is raised just once and after the last page has printed.
Use the event to release resources, notify the user that the print has finished or any other after print needs.

3. PrintPage
The PrintPage event is raised for each page and while the PrintDocument object has pages to be printed.
This is where the magic happens. Use the event to set the content that will be printed in the current page like text, images and so on.

For each printed page you’ll have to check if more pages must be printed and set the boolean property HasMorePages from the PrintEventArgs parameter to allow the event be raised again or finish the print process.

4. QueryPageSettings
The QueryPageSettings event is raised before each page prints.
Use the event to preset page level properties.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


%d bloggers like this: