Given a Visual Basic picture box object named picA.
To clear the screen
| picA.Cls | ![]() |
To print line by line
| picA.Print "Hello"
picA.Print "There!" |
![]() |
Cursor Placement (in twips)
| picA.CurrentX = 500
picA.CurrentY = 200 picA.Print "HHS" |
![]() |
Note: the text ("HHS") is precisely located by its upper left corner. |
Fonts and Font Characteristics (Properties)
| picA.ForeColor = RGB(255,0,0)
picA.FontName = "Arial" picA.FontSize = 28 |
![]() |
see the picture box's Properties window for a list of fonts & sizes available on your computer |
Lines are determined by the coordinates of their endpoints.
To draw a line from (440,320) to (1970,1550)
| picA.Line (440,320) - (1970,1550) | ![]() |
To set the colors of lines:
Way 1 ~ set the ForeColor property, this affects all subsequent lines
| picA.ForeColor = RGB(255, 0, 0)
picA.Line (440,320) - (1970,1550) picA.Line(270,1310) - (2170,550) |
![]() |
Way 2 ~ affects this line only
| 'the current ForeColor is black
picA.Line (440,320) - (1970,1550), RGB(255, 0, 0) picA.Line(270,1310) - (2170,550) |
![]() |
Notice that the first line is drawn in red, but the second line returns to black (the current ForeColor) |
Other settings (properties)
Always place the commands for other settings BEFORE the line or lines you wish to draw. These settings (properties) will remain in effect for all lines drawn until you change them.
picA.DrawWidth = 1 'use 1, 2, or
3
picA.DrawMode=13 'use 13 - Copy
Pen
picA.DrawStyl = 0
'0 is Solid, 1 is Dashed, 2 is Dotted, ...)
'place one or more line drawing commands here
You can find your properties and values for these properties by looking in the picture box's Properties window.
Just as circles can be divided into 360 degrees, they can also be divided into radians. Halfway around a circle is PI radians (where PI = 3.1415927...). A full circle is divided into 2 * PI radians. Like this:
Circles, Arcs, Arc Segments, Ellipses (using aspect radio)
Circles
Every circle can be identified by its center and its radius
To draw a circle whose center is at (300, 200) and whose radius is 150:
| picA.Circle (300, 200), 150 | ![]() |
The first parameter (or position), (300, 200), is the center.
The second parameter, 150, is the radius.
The circle above will be drawn in the current Forecolor, just like a line.
You can specify the color of the current circle, by adding a color value as a third parameter.
To draw the same circle, but specify red, or RGB(255, 0, 0):
| picA.Circle (300, 200), 150, RGB(255, 0, 0) | ![]() |
The first parameter (or position), (300, 200), is the center.
The second parameter, 150, is the radius.
The third parameter, RGB(255, 0, 0), is the color.
Arcs
Arcs are partial circles, that is, circles that start at a given angle and end at a given angle. To draw arcs in Visual Basic, we simply draw a circle with a starting angle and an ending angle. The angles must be expressed in Radians. Radians are most easily expressed in terms of Pi, so we define Pi in our program (usually in the General Declarations section).
Define Pi like this:
const Pi = 3.1415927
To draw a red arc whose center is at (300, 200) whose radius is 150,
whose starting angle is 0 and whose ending angle is Pi:
| picA.Circle (300, 200), 150, RGB(255, 0, 0), 0, Pi
or picA.Forecolor = RGB(255, 0, 0)
|
![]() |
The first parameter (or position), (300, 200), is the center.
The second parameter, 150, is the radius.
The third parameter, the color, is blank.
The fourth parameter, 0, is the starting angle of the arc.
The fifth parameter, Pi, is the ending angle of the arc.
To draw the bottom half of a circle:
| picA.Circle (300, 200), 150, RGB(255, 0, 0), Pi, 2 * Pi
or picA.Forecolor = RGB(255, 0, 0)
|
![]() |
To draw the first quarter of a circle:
| picA.Circle (300, 200), 150, RGB(255, 0, 0), 0, Pi/2
or picA.Forecolor = RGB(255, 0, 0)
|
![]() |
To draw the second quarter of a circle:
| picA.Circle (300, 200), 150, RGB(255, 0, 0), Pi/2, Pi
or picA.Forecolor = RGB(255, 0, 0)
|
![]() |
You can tell Visual Basic to draw the radii of the arc, creating an
arc segment, by negating the angles (put a minus sign in front of the angle).
Visual Basic doesn't read the negative as a negative radian, it reads is
only as a signal to draw the radius.
| picA.Circle (300, 200), 150, RGB(255, 0, 0), -Pi/2, -Pi
or picA.Forecolor = RGB(255, 0, 0)
|
![]() |
If you need a "negative zero", you must use a "small negative", such
as -0.001:
| picA.Circle (300, 200), 150, RGB(255, 0, 0), -0.001, -Pi/2
or picA.Forecolor = RGB(255, 0, 0)
|
![]() |
Ellipses and Aspect Ratio
Aspect Ratio is the ratio of the vertical scaling to the horizontal scaling. In simpler terms for an ellipse, it represents the "vertical stretch".
You can indicate the aspect ratio by adding a sixth parameter. If you just want an ellipse, leave the third (color), fourth (starting angle), and fifth (ending angle) parameters blank.
To draw an ellipse whose center is at (300, 200), whose horizontal radius
is 75, and whose aspect ratio is 2:
| picA.Circle (300, 200), 75, , , , 2 | ![]() |
The first parameter (or position), (300, 200), is the center.
The second parameter, 75, is the radius.
The third parameter, the color, is blank.
The fourth parameter, the starting angle of the arc, is blank.
The fifth parameter, the ending angle of the arc, is blank.
The sixth parameter, 2, is the aspect ratio.
To draw an ellipse that is "flat" in appearance, we must use an aspect ratio less than one in order to make the vertical radius shorter than the horizontal radius.
The following ellipse has an aspect ratio of 0.5, thus making it half
as high as it is wide:
| picA.Circle (300, 200), 150, , , , 0.5 | ![]() |
Circles fill with color based on the FillStyle and FillColor properties of the picturebox at the time the circle is drawn.
Arcs fill with color the same way, BUT ONLY if the two radii are drawn,
to form an arc segment. If you omit one or both radii, the fill color
will be ignored.