Книга: C# 2008 Programmer

Basics of Printing in .NET

Basics of Printing in .NET

In .NET, all the printing functionality is encapsulated within the PrintDocument control/class, which can be found in the Toolbox (see Figure 16-13). The PrintDocument control defines the various methods that allow you to send output to the printer.


Figure 16-13

To incorporate printing functionality into your Windows application, you can either drag and drop the PrintDocument control onto your form or create an instance of the PrintDocument class at runtime. This example uses the latter approach.

To start the printing process, you use the Print() method of the PrintDocument class. To customize the printing process using the PrintDocument object, there are generally three events with which you need to be acquainted:

BeginPrint — Occurs when the Print() method is called and before the first page of the document prints. Typically, you use this event to initialize fonts, file streams, and other resources used during the printing process.

PrintPage — Occurs when the output to print for the current page is needed. This is the main event to code the logic required for sending the outputs to the printer.

EndPrint — Occurs when the last page of the document has printed. Typically, you use this event to release fonts, file streams, and other resources used during the printing process.

Оглавление книги


Генерация: 1.490. Запросов К БД/Cache: 3 / 1
поделиться
Вверх Вниз