VCL.Printing Sample
Language:
This sample exemplifies how to create a small application that prints multipage documents.
Contents |
Location
You can find the printing sample project at:
- Start > Programs > Embarcadero RAD Studio > Samples > CPP > VCL > Printing
- Subversion Repository for C++: http://sourceforge.net/p/radstudiodemos/code/HEAD/tree/branches/RadStudio_XE4/CPP/VCL/Printing/
Description
This application consists of a five-page editor that has the ability to print documents.
The main form contains a printing button, a TTabSet, and a TMemo for entering the text. The text in the TMemo component changes for each of the five tabs. Clicking the Print button displays the standard Windows print dialog.
How to Use the Sample
- Navigate to Start > Programs > Embarcadero RAD Studio > Samples and open printing.cbproj
- Press F9 or choose Run > Run
Files
The project has one source file, mainform.cpp, which contains the class for the editor.
Classes
TFormMain is the class that implements the main form of the editor. It contains a print button, a TPrintDialog component, a TMemo, and a TTabSet with five tabs. TFormMAin handles the printing of the document and the text display for each of the five pages.
Implementation
- The TMemo component changes its text as different tabs from the tab set are selected.
- The text corresponding to each page is stored in a TStringList object.
- Printer returns the instance that manages the interaction with the printer.
- BeginDoc and EndDoc initialize and finish the print job.
- To add a header to the printed document, the Canvas property is used.
- Other properties of TPrintDialog are used to get the options chosen from the print dialog: TPrintDialog.Copies, TPrintDialog.Collate, TPrintDialog.PrintRange.
Uses
- TMemo
- TTabSet
- TPrintDialog
- TPrintDialog.Copies
- TPrintDialog.Collate
- TPrintDialog.PrintRange
- Printer
- TPrinter.Canvas
- BeginDoc
- EndDoc
- TStringList