Connecting Tech Pros Worldwide Forums | Help | Site Map

Drawing Graphics

debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 7,509
#1   Sep 11 '07
This article contains the basic syntax to draw graphics of various shapes and sizes in Visual Basic 6.0. Different types of geometrical shapes (rectangle, square, circle, arc, ellipse etc.) can be drawn on the form by using the following syntax.

Basic syntax (for line, rectangle, square)
=============================
Expand|Select|Wrap|Line Numbers
  1. OBJECT.LINE [STEP] (X1, Y1) [STEP] -(X2, Y2), [COLOR], [B[F]]
STEP -- KEYWORD SPECIFYING THAT THE STARTING POINT COORDINATES ARE RELATIVE TO THE CURRENT GRAPHICS POSITION GIVEN BY THE "CURRENTX" & "CURRRENTY" PROPERTIES.

X1, Y1 -- SINGLE VALUES INDICATING THE COORDINATES OF THE STARTING POINT FOR THE LINE OR RECTANGLE. IF OMITTED THE LINE BEGINS AT THE POSITION INDICATED BY CURRENTX AND CURRENTY.

STEP -- KEYWORD SPECIFYING THAT THE END POINT COORDINATES ARE RELATIVE TO THE LINE STARTING POINT.

X2, Y2--SINGLE VALUES INDICATING THE COORDINATES OF THE END POINT FOR LINE BEING DRAWN.

COLOR -- INDICATES THE COLOR OF THE LINE. CAN USE RGB() OR QBCOLOR() FUNCTIONS, OR NAMED COLOR CONSTANTS SUCH AS vbGreen.
IF OMITTED, THE CURRENT VALUE OF THE FORECOLOR PROPERTY IS USED.

B -- ("BOX") - IF INCLUDED, CAUSES A BOX TO BE DRAWN USING THE COORDINATES TO SPECIFY OPPOSITE CORNERS OF THE BOX.

F -- ("FILL") - CAN ONLY BE USED WITH "B" OPTION. IF USED, "F" SPECIFIES THAT THE BOX IS TO BE FILLED WITH SAME COLOR USED TO DRAW THE BOX. IF B IS NOT FILLED WITH F(F option is not used), THE BOX IS FILLED WITH CURRENT "FILLCOLOR" AND "FILLSTYLE". DEFAULT VALUE FOR FILLSTYLE IS TRANSPARENT.

Expand|Select|Wrap|Line Numbers
  1. Me.Line Step(7000, 5000)-Step(2000, 4000), QBColor(5), BF
Basic Syntax (for elliptical shapes - arc, circle, ellipse)
================================================
Expand|Select|Wrap|Line Numbers
  1. OBJECT.CIRCLE [STEP] (X, Y), RADIUS, [COLOR, START, END, ASPECT]
STEP -- SPECIFIES THAT THE CENTER OF THE CIRCLE OR ELLIPSE IS RELATIVE TO THE CURRENT COORDINATES GIVEN BY THE "CURRENTX" & "CURRENTY" PROPERTIES.

X, Y -- COORDINATES INDICATING THE CENTER POINT OF THE CIRCLE OR ELLIPSE.

RADIUS -- INDICATES THE RADIUS OF THE CIRCLE OR ELLIPSE.

START, END -- WHEN AN ARC (A PARTIAL CIRCLE) IS TO BE DRAWN, START AND END SPECIFY THE BEGINNING AND THE ENDING POSITION OF THE ARC.
THE RANGE FOR BOTH IS -2Pi RADIAN TO 2Pi RADIAN. THE DEFAULT VALUE FOR START IS 0 RADIANS AND THAT FOR END IS 2Pi RADIANS. IN OTHER WORDS, THE DEFAULT IS TO DRAW A COMPLETE CIRCLE OR ELLIPSE.

ASPECT -- INDICATES THE ASPECT RATIO OF THE CIRCLE/ELLIPSE. DEFAULT IS 1.0, WHICH YIELDS A PERFECT CIRCLE ON ANY SCREEN.

Expand|Select|Wrap|Line Numbers
  1. Me.Circle (ScaleWidth / 2, ScaleHeight / 2), Switch(ScaleWidth >= ScaleHeight, ScaleHeight / 2, ScaleWidth < ScaleHeight, ScaleWidth / 2), vbRed, 0, 3, 0.8
Hope it helps the user to draw any basic objects on form or picturebox.



Moderator
 
Join Date: Oct 2006
Location: Australia
Posts: 7,748
#2   Sep 12 '07

re: Drawing Graphics


I've just been doing a bit of editing, to correct a bit of the English and so on. I'm concerned about the text for the BF options on Line. You seem to be contradicting yourself. First you say the box will be filled with "the same color used to draw the box", then you say it's FillColor.

Which is it? (I can't remember.)
debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 7,509
#3   Sep 12 '07

re: Drawing Graphics


Quote:

Originally Posted by Killer42

I've just been doing a bit of editing, to correct a bit of the English and so on. I'm concerned about the text for the BF options on Line. You seem to be contradicting yourself. First you say the box will be filled with "the same color used to draw the box", then you say it's FillColor.

Which is it? (I can't remember.)

Thanx for pointing to the error.
Actually this is a TYPO . I missed the NOT by mistake.
Any more suggestions are most welcome.
Moderator
 
Join Date: Oct 2006
Location: Australia
Posts: 7,748
#4   Sep 13 '07

re: Drawing Graphics


Quote:

Originally Posted by debasisdas

Thanx for pointing to the error.
Actually this is a TYPO . I missed the NOT by mistake.
Any more suggestions are most welcome.

Ah. Well, I've learned something there. I didn't know the relationship between the F option and the Fillcolor property. Have drawn boxes plenty of times, and filled them, but it was always trial and error.
Newbie
 
Join Date: Jan 2008
Posts: 3
#5   Jan 23 '08

re: Drawing Graphics


Thanks a lot .. i got the required output.
Reply