2: Add Controls
Up
Note: when you create a new project in Visual Basic, be sure to select 'Standard EXE' as the desired project type.

The types of control that are available in the toolbox are called 'intrinsic controls' it is possible to add other control to a VB project by choosing Components... in the Project menu. Even more controls can be obtained by downloading them from the Internet.

 

As mentioned, the user interface is ‘drawn’ in the form window.  There are two ways to place controls on a form:

1.     Double-click the tool in the toolbox and it is created with a default size on the form.  You can then move it or resize it.

2.     Click the tool in the toolbox, then move the mouse pointer to the form window.  The cursor changes to a crosshair.  Place the crosshair at the upper left corner of where you want the control to be, press the left mouse button and hold it down while dragging the cursor toward the lower right corner.  When you release the mouse button, the control is drawn.

·       To move a control you have drawn, click the object in the form window and drag it to the new location.  Release the mouse button.

·       To resize a control, click the object so that its select and sizing handles appear.  Use these handles to resize the object. 

What does each control do? Not all the controls will be explained here since we will not have time to learn them all. We must remember that the heart of VB programming is writing code, not creating controls.

The Pointer Tool is not used to make controls, but only to select them, move them or resize them. Using the pointer tool, a single control can be selected by clicking it or multiple controls can be selected simultaneously by dragging a selection rectangle around them all. Multiple controls can also be selected simultaneously by holding down the Shift key while you click additional controls.

The PictureBox control can contain various types of image. The PictureBox control is more powerful than the Image control (it allows images to be resized, for example) but the Image control gives smoother animations

The Label control is used for text output only - the user of your program will not be able to type into any label.

The TextBox control is used for both text input and text output.

The CommandButton control is used to trigger any sequence of actions, known as a 'procedure' or 'subroutine'.

  The CheckBox control is used to allow the user to select items that are independent and thus NOT mutually exclusive. For example, check boxes could be used to allow the user to turn on bold, italic or underline styles for some text - it should be possible to turn on these styles in any combination.

The OptionButton control is used for options that are mutually exclusive, since only one option button can be selected at any one time (clicking an option button causes other option buttons to become unselected. Option buttons could be used, for example, to align some text left, center or right. Since the text can only have ONE of these alignments at any given time, option buttons rather than check boxes should be used for the selection.

The Timer control acts like an alarm clock - it can be set to go off at regular intervals such as every 2000 milliseconds (2 seconds) and when it 'goes off' it can trigger a sequence of actions (a procedure). The Timer control can be places anywhere on the form for it will be invisible to the user.

The Shape Tool is used to create rectangles, circles etc. These shapes are not 'controls' and therefore cannot have any code attached to them.

The Line Tool is used to make lines. Like shapes, lines are not controls and therefore cannot have any code attached to them.

The Image control can display pictures. It's less powerful than the PictureBox control but allows smoother animations.

The OLE control is a powerful control used for Object Linking and Embedding. Using this control, objects such as Word objects, Excel objects, Windows Media Player objects such as movies etc can be added to forms.

Hit Counter since February 13, 2001.

Previous Up Next