Understand forms and the controls that you can place
on the
Forms and
Controls
So, how do you
draw design and construct a form for user input or
output? With Visual Basic, you have a
toolbox filled with controls. You can choose which
controls you want by dragging them onto a form.
The toolbox is shown below.
If you double-click one
of the controls in the toolbox it places a
copy of that control onto your form.
You can move a control to a different place
on the form if you wish by dragging it.
~~Activity~~
Activity A
Open Visual Basic. It should
be on the Start Menu > Programs >
Visual Studio 6 > Visual Basic.
Can you see a toolbox on the left
and a form in the middle? If not ask
your lecturer for help.
Try and make your form look like my
form shown in the picture above. Just
double click a control on the toolbox
and it will be placed in the center of
your form. Then move the control
to the proper position by dragging it.
When you have finished placing all
the controls, you can view what your
program will look like to the user by
running it. Just click on the play icon
in the toolbar near the top of Visual
Basic.
You should end up with something
like this
program. Just click the link and
choose Open.
It is not a very exciting program at the
moment because I have not added code to
make it do anything useful.
Controls and their Purpose
Each control has a different
purpose. A control will usually either be for displaying
information to the user (output) or for getting information
from the user (input).
Icon
Control Name
What it looks like on the form
What it is for
Label
Used for displaying information to the user
and labelling other controls
TextBox
Meant for user input. The user can type
information into a text box
CheckBox
Used for selecting or deselecting some
feature of the program.
ComboBox
Displays a list of items in a drop-down list
and the user selects one.
Frame
You can place other controls inside a frame
and group them nicely.
ListBox
Displays a list of items and the user can
select one.
OptionButton
Option buttons are usually grouped together
and the user chooses one.
CommandButton
The user clicks the command button.
E.g. OK, Cancel etc.
Timer
Used to get your program to execute code at
certain intervals
PictureBox
You can display pictures inside this control
VScrollBar
The slider allows the user to scroll things
such as text inside a text area, or a
picture that is too large to display all at
once.
HScrollBar
Like the vertical scrollbar, this allows the
user to scroll.
~Activity~~
Activity B
Here are some controls you can
play with.
Fill in the form
below. Then click the Submit command
button.
Changing Control Properties
Some of the controls in your
program can be made more useful by setting the
control's properties. To change the property of
a control in Visual Basic, you need to select
that control and change the property value in
the properties window. The picture
below shows the ListBox selected.
The properties window is on the right and I am
adding the numbers 1, 2, 3, 4 to the List property. Then the ListBox will display these numbers.
Here are some useful properties.
There are many others.
Caption
Property - this changes the text that is
displayed by a control. I.e. a label's
text.
List
Property - you can add items for a ComboBox or ListBox to
display.
Picture
Property - you can add a picture to your PictureBox.
The picture shows the difference when I
change some of the property values of the
different controls.
I changed the caption of the
Label to Angela
I added the items 1, 2, 3 and 4 to
the ListBox list
I added a picture to the
PictureBox.
~~Activity~~
Activity C
In the form you created in
Activity A, change the following
properties...
Change your label's Caption property so it
displays your name
Use the List property to change your ListBox so it displays
the numbers 1, 2, 3 and 4.
Add a picture to your PictureBox using
the Picture property.