In VB, graphics capabilities are usually associated with drawing lines, boxes, or otherwise manipulating the display. Graphics are usually created on something, which in the case of VB is either the printer, the screen, or the picture control. All three represent a surface to which graphics can be applied. No other control supplied with VB supports the graphics features.

I'll first walk through the graphical methods and properties which VB supports and then discuss them one at a time to help you understand how they play together.

Here are graphics methods which VB supports:

Likewise, here are the graphics properties which VB supports.


One of the first things about objects you need to undestand is the concept of scales. The obvious question to ask about an object or graphic on a screen is "How big is it?". The answer to the questions can depend on the units chosen for the measurement. Inches, centimeters, millimeters, and pixels are all common units of measurement so you won't be surprised to know that VB supports all of these. Their definition should be self- explanatory.

VB also supports other units of measuring the size of something on the screen. Specifically, it supports:


The ScaleMode property simply identifies which units are to be used. You can set it to any of the units I've already discussed above. Once you pick a scalemode, VB adjusts the size properties of the client area to match the selection.

A point to remember is that when you create graphics, you'll be creating them in the client area of the window. In general, you'll be using an X/Y position within the client area to direct VB to place graphics. The bounds of the client area are defined by the properties ScaleWidth and ScaleHeight . VB also lets you pick the top/left starting coordinates of the client area, using the properties ScaleTop and ScaleLeft. This can be useful if you know that your graphics equation only apply to an area some distance away from the coordinate origin (X=0 and Y=0).

Using Graphics Methods
As you saw up above, there are only 7 graphics methods. It's really just 6 if you consider that the PRINT method is in a class of its own. Since I already covered printing in an earlier tutorial, let's just walk through each of the remaining 6 graphics methods and see how to use them. For this exercise, I assume we have a picturebox named Picture1 on a form.

            for i = 1 to 1000 step 100

       + 500, 1000), 400, vbGreen

	Next i

The circle syntax can be pretty simple: (XCenter, YCenter), Radius, Color

There are other things you can do as well, so check out HELP for a listing of all the arguments that are available.

The .cls methods will erase all graphics which have been drawn on the object, in this case the picturebox.

            for i = 1 to 1000 step 100

                picture.line(i + 500, 500) - (i + 500, 4000), vbBlue

	Next i

The line method can also draw boxes by simply adding an extra argument to the code as follows:

            for i = 1 to 1000 step 400

                picture.line(i + 500, 500) - (i + 500, 4000), vbBlue, BF

	Next i

The BF added at the end of the line of code simply tells VB to draw a filled box instead of a line.



i = picture1.point (100,500)

Here, the color of the point located at X=100 and Y=500 is assigned to the variable i. In my own experience I haven't had any reason to use this method.

This is the most basic drawing tool VB has to offer. With PSET you can set the color of any point within the client area of the drawing surface. For example, the next code randomly picks a color and randomly picks a coordinate at which to set the color. For no good reason I limit the number of points plotted to 1000

For i = 1 to 1000
	'pick color value from 0 to 15 (the QBasic standard color set)
	iColor = (Int(15 * RND)+0
	'pick X from 0 to ScaleWidth
	X = (Int((Picture1.ScaleWidth * Rnd) + 0))
	'pick Y from 0 to ScaleHeight
	Y = (Int((Picture1.ScaleHeight * Rnd) + 0))
	'now plot the data
	picture1.pset (X,Y), QBColor(iColor)
next i
Note: To get a value from n to 15, replace the "0" with the value of n

With PSET you can do almost any graphic you can imagine, limited only by the difficulty in controlling one point at a time. Also, the PSET method is not nearly so fast as some of the higher order graphics methods.

The Bottom Line

In case it hasn't struck you yet, VB is not a graphics powerhouse. It's tools are very simple and there's just not very many of them. However, all is not lost!

You'll find that to create graphics of any sophistication will involve the use of the Windows API (Application Programmer's Interface), which are very powerful and very fast. However, even though the API are fairly powerful, they are not designed to be a graphics programmer's toolkit.

For that purpose, Microsoft has created another set of DLLs, known as DirectX. DirectX was written for the more professional programmer who is looking to create the more complicated, higher performance applications. You can get DirectX for free from Microsoft.

DirectX works essentially the same way as do the Windows API. However my own experience is very limited so all I can do is to point you off to the DirectX API and let you experiment on your own.