Visual Basic forms are windows. It's an important piece of data because it
ties the concept of a form in with everything you already know about Windows
applications. These rectangular shaped areas of the computer screen are
called windows and the whole strategy of the Windows Operating System is to
manage the display of those windows (while running the code that generates
them or which performs calculations in the background).
Since you've already been exposed to other Windows programs, then
you already intuitively understand the concept of a form (window)! This
section provides additional details about how VB handles forms.
What is a Form?
Here's a simple Visual Basic form. It looks just like any other form that
you use in Windows applications. The header area has a caption, the control
menu, and the minimize/maximize/close buttons. The the large area of the
form is called the client area.
Don't be shocked, but all Windows/NT programs consist of one or more
windows. In its simplest form, a window simply consists of a rectangular
area of the screen. Anything that appears inside that area is considered
to be part of the window. However, you can have one window contained inside
another. Control objects, which are also implemented as windows, will be
framed by the form window to which it belongs. As an operating system,
Windows 9.X/NT controls the display of the various, possibly overlapping,
windows on the screen.
In Visual Basic, the basic building block of an application is a form, which
is simply a window. The VB IDE can insert forms into your project, and then
you can resize the forms as well as change other properties of the form.
However, controls (checkboxes, textboxes, ...) are
also windows. A form is distinguished from a control in that only forms can
exist as standalone objects. When controls are used, they must be placed in
a form. Ok, there are a few exceptions such as the printer object or the
screen object which are not considered part of any form, but are part of a
VB program. I'll talk to these special "system" objects later in the
Not to confuse the issue, but controls can also be placed inside of other
controls. When this happens the parent control is known as a container.
Likewise, forms are containers but are the highest level of container there
is in a windows application. Forms are always parents of controls, never
the other way around.
There is one exception which I will not cover in these tutorials, and that
is a special form called an MDI form. In this special case, an MDI form
is always contained within a parent form. This is exactly the same type of
parent/child relationship which you see in Word. Each new Word document
is contained in its own window, but is always framed within the larger
window that is the Word application.
The MDI (multiple document interface) forms can be very useful in applications
where multiple files/images/documents need to be open at the same time. Other
than this brief mention, I will not cover MDI forms in these tutorials.
Properties / Events / Methods
Now is a good time to bring up the 3 categories of information which may
be used to describe any object, including forms. Forms, like any object,
have properties which you may set. The properties range from the caption
that the form displays to the physical size of the form. Later on this
page I list all of the properties/events/methods that a form recognizes.
Likewise, a form may recognize certain events. All forms recognize the
same events, but there are controls which recognize a broader range of
events than forms. Events range from a simple keypress by the user to the
click of a mouse button.
Then, finally, forms and controls also support various actions that may be
taken. The actions are known as methods, and may include such tasks as
moving the form, loading it into memory, or refreshing the form to redraw
graphics which may have been overshadowed when one form was placed on top
Remember that even though this part of the tutorial is focussing on forms,
that Properties/Events/Methods apply to all objects in Visual Basic.
Given that there are over 20 controls available to you in the VB Pro edition,
you might be concerned that learning all of the possible properties, events,
and methods could be an overwhelming task. However, it's not at all that bad.
Here's a very helpful piece of information that makes your task easier:
all forms, controls, or objects share many of their properties, events,
and methods!. Re-read what I just wrote! It's a very important piece
of information and it means you can reuse what you learn about one control
to help you learn about other controls.
I've created a control summary chart (available in
Excel 97 and
Excel 5.0 formats.
The chart gives the complete list of VB
controls (provided in VB Pro) and lists their properties, events, and methods.
The chart is listed in such a way that you can see the common items, as well as those
which are unique to that control. You'll see that many controls have
no unique items at all! In my chart I show 41 common properties, 20
common events, and 7 common methods. Please note that not every control
uses all the common items! Some common items may be shared by only 2 or 3
I highly recommend that you look over the chart and become familiar with
all of the items on it. I regularly get questions at my site where
the programmer could have performed a desired task by simply setting a
property of the control, if he had just known about it! Just having
the chart gives you the ability to look and see if a control supports a
feature that you need.
Detailed descriptions and sample code for using the items can be found in
the VB HELP file. There is also a Microsoft book call "The VB6 Language
Reference" which gives additional detail for each of the items.
As a prelude to the larger chart, here's a simple listing of the entire
set of properties, events, and methods that are recognized by a form.
Don't shy away from looking at this list in detail because you will
use every one of these over and over again! Forms are particularly critical
to the VB programmer because they are the fundamental building block for
You'll note that forms, like most objects tend to have many properties, and
that the number of events is much larger than the number of methods. A
control can have well over 100 properties but normal count is usually around
50-70. You'll find that the name of most of the properties to be very
self-explanatory (i.e., caption, name, fontsize, enabled, ...).
On the other hand, controls are not likely to have more than 25
or so events, and rarely has more than 10 methods. There are exceptions,
but the generalization gives you a feel for what is involved with most
The control summary chart lets you quickly
get to details of which controls supports which item.