We can create a simple virtual drawing program using Visual Basic 6 as shown in the diagram below. We called it drawing pad.
In this program, the user needs to fill in all the coordinates and chooses a color before he or she can proceed to draw the required shape. If he or she forgets to fill in the coordinates or chooses a color, he or she will be prompted to do so.
To create the drawing pad, you need to insert a common dialog control, a picture box, four text boxes , six command buttons and the necessary labels. The function of the common dialog control is to assist the users to choose colors. The text boxes are for the user to enter the coordinates and the picture box is to display the pictures drawn.
The syntax to draw a straight line is Line, and the syntax is as follows:
Picture1.Line (x1, y1)-(x2, y2), color
where picture1 is the picture box, (x1,y1) is the coordinates of the starting point, (x2, y2) is the ending point and color understandably is the color of the line.
The syntax to draw a non-solid rectangle is
Picture1.Line (x1, y1)-(x2, y2), color, B
The syntax to draw a solid rectangle is
Picture1.Line (x1, y1)-(x2, y2), color, BF
The syntax to draw a circle is
Picture1.Circle (x3, y3), r, color
Where (x3, y3) is the center of the circle and r is the radius.
if you wish to draw a solid circle and fill it with the selected color, then add two more lines to the above syntax:
Picture1.FillStyle = vbSolid
Picture1.FillColor = color
The syntax to clear the picture is
Copyright ® 2008 Dr.Liew Voon Kiong . All rights reserved |Contact: firstname.lastname@example.org