A BOOKLET EXAMPLE

The UsePrintPreviewDialog example program described earlier draws some text centered on the program’s three pages of printout. This section describes a more useful example that prints a long series of paragraphs that may each use a different font size.

The PrintBooklet example program, which is available for download on the book’s website, figures out how to break the text into pages. It assumes that you will print the pages double-sided and then later staple the results into a booklet. To allow extra room for the staples, the program adds a gutter to the margin of each page on the side where the staples will be. The program assumes that you will place the first page on the outside of the booklet, so it adds the gutter to the left margin on odd-numbered pages and to the right margin on even-numbered pages. Finally, the program displays a page number in the upper corner opposite the gutter.

In addition to demonstrating event handlers for the PrintDocument class’s events, this example shows how to use StringFormat objects to align text and break lines at word boundaries, wrap text within a target rectangle, and measure text to see how much will fit in a target rectangle.

Figure 27-4 shows the PrintBooklet program’s print preview dialog box, so you can understand the goals. If you look closely, you can see that the left margins on the first and third pages and the right margin on the second page are enlarged to allow room for the gutter. (Imagine the second page ...

Get Visual Basic 2012 Programmer's Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.