Visual Basic/Simple Graphics

This chapter is a simple introduction to drawing simple graphics in Visual Basic Classic. It is possible to do very sophisticated graphics programming in VB but here we will concentrate of the basics.

There are two ways of creating simple two dimensional graphics in VB:


 * draw lines, boxes, circles, and ellipses at run time by executing statements or


 * add shape objects to the form at design time.

If you know in advance exactly what to draw, then it might be simpler to use the second method, as you can then see exactly what you will get as you drag and drop shapes to the form. However if the picture is to be generated based on, say, some statistics, you might be better off using the drawing methods of a Form or PictureBox.

Shape and Line controls
There are two built-in controls in Visual Basic that can be used to create simple two-dimensional drawings:


 * Shape
 * Line

Here is a simple example showing some of the shapes that can be created simply by dropping Shape controls on a Form:

Note that you can modify the properties of Shape and Line controls at run time just as you can any other control. You can also create them at run time, either by using Control Arrays or by using the CreateObject function.