Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

376 Part III Designing the User Interface


Adding Artwork by Using


the System.Drawing Namespace


Adding ready-made artwork to your programs is easy in Visual Basic. Throughout this book,
you’ve experimented with adding bitmaps and icons to a form by using picture box objects.
Now you’ll learn how to create original artwork on your forms by using the GDI+ functions
in the System.Drawing namespace, an application programming interface (API) provided
by the Microsoft .NET Framework for creating two-dimensional vector graphics, imaging,
and typography within the Windows operating system. The effects that you create can add
color, shape, and texture to your forms.

Using a Form’s Coordinate System


The first thing to learn about creating graphics is the layout of the form’s predefined
coordinate system. In Visual Basic, each form has its own coordinate system. The coordinate
system’s starting point, or origin, is the upper-left corner of a form. The default coordinate
system is made up of rows and columns of device-independent picture elements, or pixels,
which represent the smallest points that you can locate, or address, on a Visual Basic form.

In the Visual Basic coordinate system, rows of pixels are aligned to the x-axis ( horizontal
axis), and columns of pixels are aligned to the y-axis (vertical axis). You define locations
in the coordinate system by identifying the intersection of a row and a column with the
notation (x, y). For example, if you decide to place a picture box object on a form in your
project, the (x, y) coordinates for the object will indicate where the upper-left corner
of the picture box is located on the form. Also keep in mind that the (x, y) coordinates
of the upper-left corner of a form are always (0, 0)—that is the origin that everything is
measured from.

Visual Basic works in collaboration with your computer’s video display driver software to
determine how pixels are displayed on the form and how shapes such as lines, rectangles,
curves, and circles are displayed. Occasionally, more than one neighboring pixel is turned
on to display a particular shape, such as a diagonal line that appears on a form. The logic
that handles this type of rendering isn’t your responsibility—it’s handled by your display
adapter and the drawing routines in the GDI+ graphics library. Occasionally, this will produce
a distorted or jagged result, but it is rarely anything more than a slight visual glitch.

The System.Drawing.Graphics Class


The System.Drawing namespace includes numerous classes for creating artwork and special
effects in your programs. In this section, you’ll learn a little about the System.Drawing.
Graphics class, which provides methods and properties for drawing shapes on your forms.
You can learn about the other classes by referring to the Visual Studio Help documentation.
Free download pdf