Game Development Reference
This chapter covered the full implementation of a PrintDocument class that can print
arbitrary text with varying fonts and page settings. The user can select which printer
to use and can modify page properties before printing. In addition to configura-
tion, the user can also bring up a print preview dialog that shows the document as
it would print out before actually committing himself to a print job.
Although this chapter did not cover printing graphics, remember that the
PrintPage event handler is passed a Graphics context that functions like any other
context. You can call methods like FillRectangle() or DrawEllipse() on it and
achieve the desired effect. It is a little trickier when you start introducing graphics,
because you need to implement some form of flow layout to determine the lines
per page and how you position your content when printing.
The Companion Web site contains the full source code from this chapter, along
with an example utilizing the custom print logic. Figure 21.4 shows the interface
of the example, which is simply a front-end to the code discussed throughout this
Figure 21.4 Screenshot of the Companion Web site example.