0% found this document useful (0 votes)
242 views2 pages

Graphics Techniques With Visual Basic

This document provides an overview of graphics techniques that can be used with Visual Basic. It discusses how graphics methods can be used to draw lines, boxes and circles on forms and picture boxes. It explains that the AutoRedraw property or Paint event should be used to maintain drawings when a form is obscured and restored. It also introduces the PSet method for setting individual points and describes the default coordinate system used for graphics methods.

Uploaded by

Arun Kumar Garg
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
242 views2 pages

Graphics Techniques With Visual Basic

This document provides an overview of graphics techniques that can be used with Visual Basic. It discusses how graphics methods can be used to draw lines, boxes and circles on forms and picture boxes. It explains that the AutoRedraw property or Paint event should be used to maintain drawings when a form is obscured and restored. It also introduces the PSet method for setting individual points and describes the default coordinate system used for graphics methods.

Uploaded by

Arun Kumar Garg
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Graphics Techniques with Visual Basic

Review and Preview


In past classes, we've used some graphics tools: line tools, shape tools, image
boxes, and picture boxes. In this class, we extend our graphics programming
skills to learn how to draw lines and circles, do drag and drop, perform simple
animation, and study some basic plotting routines.

Graphics Methods

Graphics methods apply to forms and picture boxes (remember a picture box is
like a form within a form). With these methods, we can draw lines, boxes, and
circles. Before discussing the commands that actually perform the graphics
drawing, though, we need to look at two other topics: screen management and
screen coordinates.

In single program environments (DOS, for example), when something is drawn on
the screen, it stays there. Windows is a multi-tasking environment. If you switch
from a Visual Basic application to some other application, your Visual Basic form
may become partially obscured. When you return to your Visual Basic
application, you would like the form to appear like it did before being covered. All
controls are automatically restored to the screen. Graphics methods drawings
may or may not be restored - we need them to be, though. To accomplish this, we
must use proper screen management.

The simplest way to maintain graphics is to set the form or picture box's
AutoRedraw property to True. In this case, Visual Basic always maintains a
copy of graphics output in memory (creates persistent graphics). Another way
to maintain drawn graphics is (with AutoRedraw set to False) to put all graphics
commands in the form or picture box's Paint event. This event is called whenever
an obscured object becomes unobscured. There are advantages and
disadvantages to both approaches (beyond the scope of discussion here). For
now, we will assume our forms won't get obscured and, hence, beg off the
question of persistent graphics and using the AutoRedraw property and/or Paint
event.

All graphics methods described here will use the default coordinate system:
Scale Width

0,0

Scale Height
Note the x (horizontal) coordinate runs from left to right, starting at 0 and extending
to ScaleWidth - 1. The y (vertical) coordinate goes from top to bottom, starting at
0 and ending at ScaleHeight - 1. Points in this coordinate system will always be
referred to by a Cartesian pair, (x, y). Later, we will see how we can use any
coordinate system we want.

ScaleWidth and ScaleHeight are object properties representing the “graphics”


dimensions of an object. Due to border space, they are not the same as the
Width and Height properties. For all measurements in twips (default coordinates),
ScaleWidth is less than Width and ScaleHeight is less than Height. That is, we
can’t draw to all points on the form.

PSet Method:
To set a single point in a graphic object (form or picture box) to a particular color,
use the PSet method. We usually do this to designate a starting point for other
graphics methods. The syntax is:

ObjectName.PSet (x, y), Color

where ObjectName is the object name, (x, y) is the selected point, and Color is
the point color (discussed in the next section). If the ObjectName is omitted, the
current form is assumed to be the object. If Color is omitted, the object's
ForeColor property establishes the color. PSet is usually used to initialize some
further drawing process.

Pset Method Example:

This form has a ScaleWidth of 3975 (Width 4095) and a ScaleHeight of 2400
(Height 2805). The command:

PSet (1000, 500)


will have the result:

3975

You might also like