Section 17.2. Drawing Classes and the Coordinate System


17.2. Drawing Classes and the Coordinate System

Figure 17.1 depicts a portion of namespace System.Drawing, including several graphics classes and structures covered in this chapter. Namespaces System.Drawing and System.Drawing.Drawing2D contain the most commonly used GDI+ components.

Figure 17.1. System.Drawing namespace's classes and structures.


Class Graphics contains methods used for drawing Strings, lines, rectangles and other shapes on a Control. The drawing methods of class Graphics usually require a Pen or Brush object to render a specified shape. The Pen draws shape outlines; the Brush draws solid objects.

The Color structure contains numerous Shared properties that set the colors of various graphical components, plus methods that allow users to create new colors. Class Font contains properties that define unique fonts. Class FontFamily contains methods for obtaining font information.

To begin drawing in Visual Basic, we first must understand GDI+'s coordinate system (Fig. 17.2), a scheme for identifying every point on the screen. By default, the upper-left corner of a GUI component (such as a Panel or a Form) has the coordinates (0, 0). A coordinate pair has both an x-coordinate (the horizontal coordinate) and a y-coordinae (the vertical coordinate). The x-coordinate is the horizontal distance (to the right) from the upper-left corner. The y-coordinate is the vertical distance (downward) from the upper-left corner. The x-axis defines every horizontal coordinate, and the y-axis defines every vertical coordinate. Programmers position text and shapes on the screen by specifying their (x, y) coordinates. Coordinate units are measured in pixels ("picture elements"), which are the smallest units of resolution on a display monitor.

Figure 17.2. GDI+ coordinate system. Units are measured in pixels.


Portability Tip 17.1

Different display monitors have different resolutions, so the density of pixels on monitors will vary. This might cause the sizes of graphics to appear different on different monitors.


The System.Drawing namespace provides several structures that represent sizes and locations in the coordinate system. The Point structure represents the x-y coordinates of a point on a two-dimensional plane. The Rectangle structure defines the loading width and height of a rectangular shape. The Size structure represents the width and height of a shape.



Visual BasicR 2005 for Programmers. DeitelR Developer Series
Visual Basic 2005 for Programmers (2nd Edition)
ISBN: 013225140X
EAN: 2147483647
Year: 2004
Pages: 435

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