Game Development Reference
stopping with an EndPrint event. You do not really have to do much with the begin
and end events; the core logic exists in the PrintPage event. This event is passed a
PrintPageEventArgs parameter that contains a property called HasMorePages . If this
property is set to true, a new page is created and the PrintPage event is raised again
when the event handler returns.
The pseudologic for the PrintPage event handler is basically: Print the page content
using the page setting information provided, using the Graphics context provided.
Determine if more pages are needed to completely print all the content for the
document. If yes, set HasMorePages to true; otherwise set it to false.
The following code shows how to instantiate a PrintDocument , wire up to the
PrintPage event handler, and start printing.
PrintDocument printDocument = new PrintDocument();
printDocument.PrintPage += new PrintPageEventHandler(printDocument_PrintPage);
The following code describes the simplest implementation of the PrintPage event
handler, assuming that no additional pages are needed.
private void printDocument_PrintPage(Object sender, PrintPageEventArgs e)
string outputText = “Game Engine Toolset Development rocks!”;
Font printFont = new Font(“Verdana”,
Complex printing logic that you wish to reuse across multiple places requires that
you inherit from PrintDocument , handling the PrintPage event by overriding the
OnPrintPage method instead of using the event handler. The following code shows
a sample implementation of a PrintDocument that correctly handles text printing
that spans multiple pages with varying font and page settings.