Working With Graphics
Working With Graphics
METHODS:
Graphical methods allows us to draw on the form and the picturebox control.
The comon graphic methods are
PRINT:
It prints some text on the form or on the picturebox control.
CLS:
This method is used to clear the surface of the form or the picture box control.
It clears any drawing created by the graphic methods.
If some texts are present,we can use the Cls method to remove the texts.
Point:
The Point method returns the color value from an image for a pixel at a particular point.
This method is generally used to retrieve color values from bitmaps.
Refresh:
The refresh method redraws a control or object.
In other words, it refreshes the control.
Generally, controls are refreshed automatically most of the times.
But in some cases, we need to refresh a control’s appearance manually by explicitly
invoking the Refresh method.
PSet:
The PSet method sets the color of a single pixel on the form.
This method is used to draw points.
Line:
The Line method draws a line.
Using the Line method, we can also draw other geometric shapes such as rectangle,
triangle etc.
Circle:
The Circle method draws a circle.
Using the Circle method, we can also draw other geometric shapes such ellipses, arcs
etc.
PaintPicture:
The PaintPicture method displays an image on the form at run-time.
TextHeight:
The TextHeight method returns the height of a string on the form at run-time.
TextWidth:
The TextWidth method returns the width of a string on the form at run-time.
PROPERTIES:
DrawMode:
The DrawMode property sets the mode of drawing for the appearance of output from
the graphic methods.
In the DrawMode property, we can choose from a variety of values.
DrawStyle:
The DrawStyle property sets the line style of any drawing from any graphic methods.
It allows to draw shapes of different line styles such as solid, dotted, dashed shapes
etc.
DrawWidth:
The DrawWidth property sets the line width of any drawing from any graphic methods.
While drawing shapes, we can control the thickness of the lines using this property.
FillColor:
The FillColor property is used to fill any shapes with a color.
we also use the symbolic color constants to fill our shapes.
we also use the color codes as well as the RGB function.
FillStyle:
The FillStyle property lets us to fill shapes in a particular filling style.
ForeColor:
The ForeColor property is used to set or return the foreground color.
AutoRedraw:
Set the AutoRedraw property to True to get a persistent graphics when we 're calling
the graphic methods from any event, but not from the Paint event.
ClipControls:
Set the ClipControls property to True to make the graphic methods repaint an object.
Picture:
The Picture property is used to set a picture.
Pictures can be set both at design time and run-time.
CurrentX and CurrentY are the run-time properties which are used to set and return the
position of a shape or point at run-time.
CurrentX:
The CurrentX property sets or returns the horizontal coordinate or X-coordinate of the
current graphic position at run-time.
CurrentY:
The CurrentY property sets or returns the vertical coordinate or Y-coordinate of the
current graphic position at run-time.
PSET METHOD
PSET:
The Pset method draw a dot on the screen.
syntax:
Pset (x , y ), color
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
object --> Optional. Object expression that evaluates to an object in the Applies To list.
If object is omitted, the Form with the focus is assumed to be object.
Step--> Optional. Keyword specifying that the starting point coordinates are relative to
the current graphics position given by the CurrentX and CurrentY properties.
(x1, y1) -->optional. Single values indicating the coordinates of the starting point for the
line or rectangle.The ScaleMode property determines the unit of measure
used.If omitted, the line begins at the position indicated by CurrentX and CurrentY.
Step--> Optional. Keyword specifying that the end point coordinates are relative to the
line starting point.
(x2, y2)-->Required. Single values indicating the coordinates of the end point for the line
being drawn.
color-->Optional. Long integer value indicating the RGB color used to draw the line.If
omitted, the ForeColor property setting is used. we can use the RGB function or
QBColor function to specify the color.
B-->Optional. If included, causes a box to be drawn using the coordinates to specify
opposite corners of the box.
F--> Optional. If the B option is used, the F option specifies that the box is filled with the
same color used to draw the box. we cannot use F without B. If B is
used without F, the box is filled with the current FillColor and FillStyle.The default value
for FillStyle is transparent.
Example:
Line (0, 0)-(2000, 2000), vbBlue
To draw a box:
example:
Line (0, 0)-(2000, 2000), vbBlue,b
To draw a filled box:
example:
Line (0, 0)-(2000, 2000), vbBlue,bf
object--> Optional. Object expression that evaluates to an object in the Applies To list.
If object is omitted, the Form with the focus is assumed to be object.
Step -->Optional. Keyword specifying that the center of the circle, ellipse, or arc is
relative to the current coordinates given by the CurrentX and
CurrentY properties of object.
(x, y)-->Required. Single values indicating the coordinates for the center point of the
circle, ellipse, or arc.The ScaleMode property of object
determines the units of measure used.
radius -->Required. Single value indicating the radius of the circle, ellipse, or arc.The
ScaleMode property of object determines the unit of measure used.
color--> Optional. Long integer value indicating the RGB color of the circle's outline. If
omitted, the value of the ForeColor property is used. You can use the RGB function or
QBColor function to specify the color.
start, end -->Optional. Single-precision values.When an arc or a partial circle or ellipse is
drawn, start and end specify (in radians) the beginning and end positions of the arc. The
range for both is 2 pi radians to 2 pi radians. The default value for start is 0 radians;
the default for end is 2 * pi radians.
aspect --> Optional. Single-precision value indicating the aspect ratio of the circle. The
default value is 1.0, which yields a perfect (non-elliptical) circle on any screen.
Example:
Circle (1800, 1800), 1000, vbRed
DrawMode
What is draw mode?
This is a property which is used to sets the appearance from the graphics methods or of
a shape or line control.
It holds the value from 1 to 16
1-Blacknes
2.Not merge pen
3.Mask Not Pen
4.Not Copy Pen
5.Mask Pen Not
6.Invert
DRAW STYLE
What is Draw Style?
0-Solid
1-Dash
2-dot
3-Dash-Dot
4-Dash-dot-Dot
5-Transparent
6-Inside solid
DRAW WIDTH
What is Draw width?
Returns/Sets The line width for output from Graphics methods.
FILL COLOR
What is Fill color?
Returns/Sets the color used to fill in shapes,circles,and boxes
FILL STYLE
What is FillStyle?
0-solid
1-Transparent
2-Horizontal line
3-Vertical line
4-upward diagonal
5-downward digonal
6-cross
7-Diagonal cross
Syntax
LoadPicture([filename], [size], [colordepth],[x,y])
Example:
Pict1 = LoadPicture("C:\Windows\Greenstone.bmp")
RGB FUNCTION
Returns an Integer value representing an RGB color value from a set of red, green and
blue color components.
SYNTAX:
RGB( _
Red As Integer, _
Green As Integer, _
Blue As Integer _
)
Red-->Required. Integer in the range 0–255, inclusive, that represents the intensity of
the red component of the color.
Green-->Required. Integer in the range 0–255, inclusive, that represents the intensity of
the green component of the color.
Blue-->Required. Integer in the range 0–255, inclusive, that represents the intensity of
the blue component of the color.
EXAMPLE:
This example shows how the RGB function is used to return a whole number
representing an RGB color value.