Chris's Event Programming with Visual Basic course.
Contents
| Introduction | Tool Bars & Control Arrays |
Tool Bars & Control
Arrays
Tool bars can be attached to forms in two ways; either by provision
of a custom control or by the building of a control array.
Arrays of Most controls can be built, in our example we will build an
array consisting of 3 image boxes. Drag a picture box onto Form1, this
will be the container for our array. Set it’s Align property to 1, this
fixes it below the menu bar, then, drag an image box onto the picture box.
From the Edit Menu, choose copy, then choose paste. You are prompted to
choose if you want to build an array, click the Yes button, then paste
a third image box onto the form. The controls all now share the same name
(the array name) and are indexed, e.g. Image1(0), Image1(1) etc. The images
can all be aligned below the menu for form1 and ,using the picture property
for each image, an icon can be ascribed to each element of the array (I
chose Flags of the world). To give our form some functionality, add a text
box, Text1, with the default value for text blank. The design should
resemble that below:-
Now the control array is coded to control the output in the text box,
as follows:-
Sub Image1_Click (index As Integer)
Select Case index
Case 0
text1.Text = "Canada"
Case 1
text1.Text = "France"
Case 2
text1.Text = "Germany"
End Select
End Sub
When this is now run, the tool bar controls the output to the text field.
Visual Basic and all other Microsoft products mentioned
in this series are trademarks of the Microsoft Corporation.