10.14. Print a Simple Document

Problem

You need to print text or images.

Solution

Create a PrintDocument, and write a handler for the PrintDocument.PrintPage event that uses the DrawString and DrawImage methods of the Graphics class to print data to the page.

How It Works

The .NET Framework uses an asynchronous event-based printing model. To print a document, you create a System.Drawing.Printing.PrintDocument instance, configure its properties, and then call its Print method, which schedules the print job. The common language runtime (CLR) will then fire the BeginPrint, PrintPage, and EndPrint events of the PrintDocument class on a new thread. You handle these events and use the provided System.Drawing.Graphics object to output data to the page. ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.