03.01.2015 Views

C# 5.0 Programmer's Reference

Visual Studio 2013 C# 5.0 Programmer's Reference

Visual Studio 2013 C# 5.0 Programmer's Reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

364 ❘ CHAPTER 16 Printing<br />

The PrintPage event handler does all the drawing. It starts by setting the Graphics object’s<br />

SmoothingMode property to make drawn shapes smoother. (Download the example, and comment<br />

this out to see what the difference is.)<br />

Drawing Details<br />

The SmoothingMode values and many other useful values for specifying graphics<br />

characteristics such as dash style and join style are defined in the System.Drawing<br />

.Drawing2D namespace. In a program in which you do a lot of drawing, you will<br />

probably want to include the following directive.<br />

using System.Drawing.Drawing2D;<br />

Next, the program draws an orange rectangle showing the page’s margin bounds. Normally, anything<br />

you draw should be inside the margin bounds. (Don’t worry too much yet about how to draw<br />

shapes. The following sections explain drawing basics.)<br />

Depending on the page number, the code then draws a triangle, diamond, or ellipse. The event<br />

handler finishes by incrementing NextPage and setting e.HasMorePages to true if the next page<br />

has a number less than or equal to 2.<br />

Out of Bounds<br />

The e.MarginBounds value tells you where you should print to leave a reasonable<br />

margin around the edges of the page, but most printers can print outside of those<br />

bounds.<br />

The e.PageBounds value gives the size of the paper, but most printers cannot print<br />

all the way up to the edges of the paper.<br />

The e.PageSettings.PrintableArea value gives the area on which the printer<br />

should print, at least in theory.<br />

All three of these areas are measured in hundredths of inches.<br />

The following table shows the values for my printer.<br />

Value X Y Width Height<br />

e.MarginBounds 100 100 650 900<br />

e.PageBounds 0 0 850 1100<br />

e.PageSettings<br />

.PrintableArea<br />

25 6.833333 800 1042.667<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!