Wednesday, December 12, 2012

Discuss graphics method in VB with example


The Pset Method: The Pset method draw a dot on the screen, it takes the format
Pset (x , y ), color
(x,y) is the coordinates of the point and color is its color. To specify the color, you can use the color codes or the standard VB color constant such as VbRed, VbBlue, VbGeen and etc. For example, Pset(100,200), VbRed will display a red dot at the (100,200) coordinates.

The Pset method can also be used to draw a straight line on the form. The procedure is
For x= a to b
Pset(x,x)
Next x
This procedure will draw a line starting from the point (a,a) and to the point (b,b). For example, the following procedure will draw a magenta line from the point (0,0) to the point (1000,1000).
For x= 0 to 100
Pset(x,x) , vbMagenta
Next x

(b) The Line Method: Although the Pset method can be used to draw a straight line on the form, it is a little slow. It is better to use the Line method if you want to draw a straight line faster. The format of the Line command is shown below. It draws a line from the point (x1, y1) to the point (x2, y2) and the color constant will determine the color of the line.
Line (x1, y1)-(x2, y2), color
For example, the following command will draw a red line from the point (0, 0) to the point (1000, 2000).                         Line (0, 0)-(1000, 2000), VbRed
The Line method can also be used to draw a rectangle. The format is
Line (x1-y1)-(x2, y2), color, B
The four corners of the rectangle are (x1-y1), (x2-y1), (x1-y2) and (x2, y2)
Another variation of the Line method is to fill the rectangle with a certain color. The format is
Line (x1, y1)-(x2, y2), color, BF

(c) The Circle Method: The circle method takes the following format
Circle (x1, y1), radius, color
That draws a circle centered at (x1, y1), with a certain radius and a certain border color. For example, the procedure
Circle (400, 400), 500, VbRed
draws a circle centered at (400, 400) with a radius of 500 twips and a red border.