Visual Basic 2008 Programming: Business Applications with a Design Perspective
Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9
Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14 Appendix A Appendix B Appendix C Home
Last change: February 13 2016 18:48:19.

 Chapter in PDF

Table of Contents

Appendix B: Graphics, Animation, Drag and Drop
Last change: February 13 2016 18:47:46.

B.1. Drawing Graphs

VB 2008 provides support for graphics with several namespaces: The System.Drawing namespace provides access to GDI+ (improved version of Graphic Device Interface) basic graphics functionality. More advanced functionality is provided in theSystem.Drawing.Drawing2D, System.Drawing.Imaging, and System.Drawing.Text namespaces.
The discussion here is limited to the functionality provided in the System.Drawing namespace. To draw a graph on a control, there must be a graphics object (representing the drawing surface) associated with the control. The graphics object provides various methods to perform drawing. The following table gives a selected list of these methods:

Method Use
DrawEllipse Draw an ellipse within a specified rectangle.
DrawLine Draw a line between two specified points.
DrawPolygon Draw a polygon with the specified points.
DrawRectangle Draw a rectangle over two specified points.
DrawString Write specified text with a specified font at a specified location.

Each method requires a pen that specifies the color and the pen size in pixels. Different methods require different additional parameters. For example, the DrawEllipse and the DrawRectangle methods require a rectangle structure as the second parameter, while the DrawLine method requires two points.

The drawing methods draw an outline for the specified shapes. To paint the interior of the shape with a color, you use the corresponding fill methods. For example, to fill an ellipse, you will use the FillEllipse method. Before discussing these methods in detail, let’s first take a look at a few concepts that are fundamental to graphics.
Last change: February 13 2016 18:47:45.
  1. B.1. Drawing Graphs
    1. Basic Concepts
    2. The Graphic Object
    3. The DrawRectangle and DrawEllipse Methods
    4. The Fill Methods and the Brushes
    5. Drawing Christmas Lights: An Example
    6. The DrawString Method and Fonts
    7. <<PreviousNext>>