Main Menu

HOME

.Net
ASP
Assembly
C
C++
Delphi
HTML
Java
JavaScript Site
MySQL
PC interface
Powershell
Perl
PHP
VBScript
Visual Basic
XML

US Job listings




   Misc

   Amazon

   Links

    


Simple Graphics
 

 

Visual Basic has a shape control that can produce rectangles , circles and ovals in a variety of different styles and in a range of colours . As well as this there are also three methods Pset , Line and Circle which can be used to plot points of colour , draw lines and various boxes , circles . You can draw on a Form , PictureBox or a Printer object only . Here are some important properties explained.

ScaleMode

This is used to define the unit of measurement . The default is 1. Twip , this is a 20th of a Point . ScaleMode 2 is Pont this is the Printers measurement , there are 72 points to an inch . Fonts are generally measured in Points so you may use this when working with text . ScaleMode 3 is Pixel this is based on your screen and varies across machines . The size of pixels depends on the resolution of your monitor. Pixels are commonly used with imported graphics from graphic programs. There are other possibilities which you can use such as characters , centimetres , inches and millimetres.

DrawMode

This affects how the drawn line interacts with the background . You can choose between sixteen modes but the two most commonly used are mode 13 , Copy Pen which overwrites anything in the background with the foreground colour and mode 7 , Xor pen in this mode the the colours are distorted when overwriting other colours but if the line is drawn twice the first line is removed and the previous image is restored.

BackColor , ForeColor and FillColor

BackColor is the whole of the Form or PictureBox (the background) . ForeColor determines the actual color of the shapes , lines , text etc on a Form or PictureBox . FillColor is used for lines that appear in a box or circle if you have used a patterned FillStyle..

DrawStyle

This can be a variety of combinations from 0 - Solid to 5 -Transparent there are also a selection of dash-dot combinations . These are available with lines of DrawWidth = 1.

DrawWidth

This sets the width of the drawn lines , this is set in pixels no matter what ScaleMode is set to.

FillStyle

This is the pattern that can be drawn in a closed rectangle or circle . There are a variety of different settings but the most commonly used ones are 0 - Solid which would mean the shape is filled with the FillColor and 1 - Transparent . The other modes produce a variety of different types of hatching etc.

Line

the Line method can draw points , lines , open and filled rectangles , the syntax is 

Line Step (startx , starty) - [Step](endx , endy),Colour , BF

Everything except for Line and (endx , endy) are optional.
Step makes the co-ordinates relative to the position defined by CurrentX and CurrentY , these are system variables that record the last point plotted . If this is omitted the co-ordinates refer to the object with 0,0 at the top left.
startx , starty are the co-ordinates to start from if omitted the co-ordinates will be the CurrentX , CurrentY position. This would be the upper left corner.
Colour is the colour of the line , this can be set either using RGB or the QBColor function . If omitted the ForeColor property will be used.
B stands for block and will draw a rectangle
F stands for fill and will fill the rectangle with the Colour

Now for some examples type the following code into your Form_Paint event

when this is run you will see a line on the screen , a red outlined box and a large blue box.

Circle

With this you can draw circles , arcs and segments , the syntax is as follows 

Circle Step( x, y), radius, colour, start, end ,aspect

Step and Colour are the same as the line method.
x,y is the location of the centre of your circle
Radius defines the size of the circle
start , end set the limits of the arc , this is in radians working anti-clockwise from 0 (east) and 2*Pi radians in a full circle (6.28 approx) . If this is written as a negative the angle is converted to positive but a line is drawn from the centre to the arc. If both start and end are negative a segment is drawn and can be filled using the FillColor and FillStyle settings .
aspect sets the aspect ratio (the height and width of the shape) . A value less than 1 produces a flattened elipse more than 1 will produce a narrow ellipse.

Now for some examples , type the following in the Form_Paint event

Note that arguments that are not required their places must be taken by commas

Pset

This plots a point of colour the size of which is defined by the DrawWidth.The syntax is 

Pset [step] ( x, y) [color]

step and color are optional arguments , lets look at a fun example . Place the following code in a Form_Paint event

now place the following in the Form_Click event

Now run the program , lots of individual dots appear on the screen and clicking on the form ends the program.

 

 

 

 

 




   Sponsors
 

   Software
500 Java Tips E-book
PHP editor
PERL editor
Beginning Java
Beginning Visual Basic
Learn VB.net
Learn VB 6
VB and databases
ASP image library
C++ builder programming
C++ fundamentals

   Source Code
Operating System displayed in an excel table(VBScript)
display service info(VBScript)
What type of image(PHP)
Disk diagnostics(C)
close internet connection using DUN(VB)
Status bar text(Javascript)
Folder path and size(ASP)
Create a php file(C)

    




Copyright © 2003 by programmershelp.co.uk