All Snippets
Top 100 Snippets

By Language

GBIC >> Source Code >> Visual Basic >> Snippet

15 Graphics

'VB has limited graphics capabilities.  Most serious graphics work is done using Windows API

'Coordinate system

'Graphical controls (cannot appear on top of other controls, cannot receive focus, cannot
'serve as containers and do no have an hWnd property):

'Pictures can be displayed on:
'image control

'Graphics methods
.Cls   'clear a drawing area
.PSet   'sets color of a pixel at a specified point
.Point   'returns color value at a specified point
.Line   'draws line between two coordinates (also draws box)
.Circle   'draw circle of radius about a specified point (can also draw arcs or ellipses)
.PaintPicture  'draws a picture on a form, picturebox, or printer

'These properties affect the way graphics methods appear:
.DrawWidth  'width of lines
.BorderWidth  'width of outline on line and shape controls
.DrawStyle  'set solid or broken pattern for lines
.DrawMode  'defines what happend when one pattern is drawn on top of another

'color is a Long integer from 0 to 16,777,215 (&HFFFFFF&)
'color is represented by red, green and blue content - each with a value of 0 to 255
'RGB function is used to set colors using RGB content

iColor = RGB (R, G, B)  'R,G,B have values 0 to 255.  (0,0,0) is black.  (255,255,255) is white.
iColor = QBColor (i)   'i = 0 to 15, corresponding to VB color constants

'represent color by this syntax (Note: this is reversed from standard Internet color syntax):
iColor = &HBBGGRR&  'where BB is blue, GG is green, and RR is red content

'Non-displayed pictures
'VB offers a Picture object for loading pictures which do not need to be displayed
'The Picture object is convenient for creating animation sequences by using an array of Picture objects

Dim MyPicture As Picture
Set MyPicture = LoadPicture( "mypicture.bmp" )