Game Development Reference
In-Depth Information
chapter 21
Adding Printing Support
for Arbitrary Data
The boldness of asking deep questions may require unforeseen flexibility if
we are to accept the answers.
Brian Greene
One of the more common and important tasks in a Windows application is the
ability to print text or graphics. Printing was somewhat tricky to implement in
the days prior to .NET, but now there is a versatile framework to support it with-
in the System.Drawing.Printing namespace. The majority of the print mechanism
is within the PrintDocument class, which represents a component that sends output
to a printer. This class is very modular, so it allows you to implement either sim-
ple or complex printing logic and execute it using this class alone. Other classes
exist to support printer configuration and page setup properties such as orientation.
This chapter is all about using the managed mechanisms within the .NET Class
Framework to implement printing support within applications. You should have a
basic familiarity with the Graphics class within the System.Drawing namespace.
Printing Regular Text
The first thing that we must implement is the actual printing logic, which is done
by linking into events on PrintDocument . There is a method on PrintDocument called
Print() which, you guessed it, prints the document. When this method is called, a
BeginPrint event is fired, followed by a PrintPage event for each page, and finally
211
Search Nedrilad ::




Custom Search