5.1. The Graphics Class


The Graphics class represents a GDI+ drawing surface. A Graphics object maintains the state of the drawing surface, including the scale and units, as well as its orientation.

The Graphics class provides a great many properties. The most commonly used ones are listed in Table 5-2.

Table 5-2. Graphics class members

Property

Type

Description

Clip

Region

Read/write. Specifies the area available for drawing.

DpiX

Float/single

Read/write. The horizontal and vertical resolution (respectively) of the Graphics object in dots per inch.

DpiY

  

PageScale

Float/single

Read/write. The scaling between world units and page units for this Graphics object.

PageUnit

GraphicsUnit

Read/write. The unit of measure for page coordinates . Valid values are members of the GraphicsUnit enumeration, listed in Table 5-3.


The PageScale sets the scaling between the world units and the page units. To understand these, you must first understand coordinates.

5.1.1.

5.1.1.1. Coordinates

The French philosopher Rene Descartes (1596-1650) is best known today for stating that while he may doubt, he cannot doubt that he exists. This is summarized in his oft-quoted statement Cogito Ergo Sum ("I think; therefore, I am"). Among mathematicians, however, Descartes is known for inventing Analytical Geometry and what are now called Cartesian coordinates . In a classic Cartesian coordinate system, you envision an x-axis and a y-axis, as shown in Figure 5-2, with the origin (0,0) at the center. The values to the right of the origin and above the origin are positive, and the values to the left and below the origin are negative.

The coordinates you pass to the various drawing methods of the Graphics class are said to be World Coordinates . Unlike traditional Cartesian coordinates, World Coordinates have their origin at the upper lefthand corner, rather than in the center, and you count upward to the right and down, as shown in Figure 5-3.

5.1.1.2. Transforms introduced

These World Coordinates are transformed into page coordinates by world transformations. You'll use these world transformations (e.g., translateTransform, ScaleTransform, and RotateTransform) to set the center and the orientation of your coordinate system. When drawing a clock face, for example, it will be more convenient to set the origin (0,0) to the center of the clock.

Page transforms convert page coordinates into device coordinates: that is, pixels relative to the upper lefthand corner of the client area on your monitor. The page transforms are the PageUnit and PageScale properties of the Graphics object.

The PageUnit property chooses the unit you'll use to make your transformations and to scale your drawings. These units are one of the GraphicsUnit enumerated values shown in Table 5-3.

Figure 5-2. Cartesian coordinates


Figure 5-3. World Coordinates


Table 5-3. GraphicsUnit enumeration

Enumerated value

Unit of measure

Display

1/75 of an inch

Document

1/300 of an inch

Inch

1 inch

Millimeter

1 millimeter

Pixel

1 Pixel

Point

1/72 of an inch

World

World unit


Using the unit described by the PageUnit you can set the PageScale, which specifies the value for scaling between world units and page units. You'll see this at work later in this chapter when you'll create a scale of 2,000 units by 2,000 units that is, rather than working in pixels or inches, you'll create a logical unit that is 1/2,000 of the width (or height) of your screen.



Programming Visual Basic 2005
Programming Visual Basic 2005
ISBN: 0596009496
EAN: 2147483647
Year: 2006
Pages: 162
Authors: Jesse Liberty

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net