JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Printing Documents

The way you print documents in Visual Basic has become fairly involved, revolving around the PrintDocument class. You add an object of this class to a project, and then handle events like PrintPage, which is called every time a new page is to be printed. When it is added to a form, the PrintDocument component appears in the tray at the bottom of the Windows form designer.

You're responsible for handling the printing yourself-you are passed a Graphics object, and you use the methods of that object, like DrawString, which draws strings of text, to draw the document you want printed. Because this graphics object corresponds to the printer, what you draw with it will appear in the printer.

For some reason, all the examples you see on this topic only print out a single page, so I'll make it a point here to show how you handle multipage documents as well. In this case, our example, called Printing on the CD-ROM, is designed to print out two pages, one with a red rectangle, and one with a blue rectangle. You'll find Print, Print Preview, and Page Setup menu items in that example's File menu.

Besides PrintDocument objects, there are a number of dialog boxes you use to support printing. The first of these is the Print dialog itself.

Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor