Chapter 9. Graphics

Introduction

The recipes in this chapter introduce the powerful, fast, and creative graphics capabilities of Visual Basic 2005. They provide working examples of everything from drawing simple lines to creating charts and simple animations. If you’re coming from Visual Basic 6.0, you’ll be especially pleased with the powerful new capabilities of the GDI+ graphics. Several recipes will help you update your skills by substituting new functionality for the primitive graphics commands provided by Visual Basic 6.0, such as Line, Circle, and so on.

9.1. Creating Graphics Objects

Problem

You’re just getting started with GDI+ graphics and want to know where to begin.

Solution

Sample code folder: Chapter 09\GDIObjects

Always start by defining and creating the fundamental graphics objects relied upon by all GDI+ graphics methods. These include colors, pens, fonts, brushes, and of course the Graphics object itself, the drawing surface used by all graphics drawing methods.

Discussion

The sample code in this recipe demonstrates the creation of several graphics-related objects, providing a good starting point for studying some GDI+ fundamentals. We’ll look at the code in sections.

The most common place to put drawing code is in the Paint event handler for the form or control on which you will draw:

	Private Sub Form1_Paint(ByVal sender As Object, _
	      ByVal e As System.Windows.Forms.PaintEventArgs) _
	      Handles Me.Paint

You can draw in other events or methods as well, but you’ll run into ...

Get Visual Basic 2005 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.