Simple Controls

Command buttons

A command button is a simple button that is placed on your form. A user may click on the button to do something. A good example of a command button is a Print button.

Text boxes

A text box (also called an "input box") is a box that sits on the form; if the user clicks on the box and starts typing, whatever the user types will be displayed in the text box.

Labels

Labels hold static text on the form. Think of a label as a container for text; you can't do anything with the text once your program starts running.

Labels are often used to display simple pieces of information, like a temperature or the result of a computation.

Check boxes

A check box is a little square box on your form that may contain a check in it; clicking on the box will make the check appear or disappear.

Option buttons

An option button is just like a check box, except that it's a circle with a dot in it. Also in a group of option buttons, only one option button may be selected at any one time. In order for Visual Basic to know what a "group" is, all the option buttons must be placed inside a Frame control (note that the Frame must be created before the option buttons are created).

Check boxes, on the other hand, are totally independent of each other; clicking on one doesn't affect any other check box.

Frames

A frame is a rectangle with a descriptive name displayed at the top-left of the rectangle. Frames often form the border of a collection of controls.

Frames are most useful when combined with option buttons, as all the option buttons inside a frame are related, and only one option button may be selected at any one time.

Each control has a large number of properties. When you click on a control, its properties are listed in the Properties window, on the lower-right corner of the display.

For example, every control has a Name property, listed at the top of the property list next to (Name), which is the name Visual Basic uses to refer to that control. The first Label control you create is given the default Name of Label1. The next Label is named Label2, and so on.

It is highly recommended that you change the name of your controls to more accurately reflect what that control does. For example, if you have a button labelled "Quit", which will quit the program when clicked, it makes sense to name that control "QuitButton".

Why change a control's name? Because you'll be using those names a lot later on in the code, and it's easier to refer to a control by the name "QuitButton" than by trying to remember if that's "Button8" or "Button9".

Labels and command buttons also have a Caption property. For labels, the Caption property is exactly what's displayed on the Label. For command buttons, Caption is the text that is displayed on top of the button.

Text boxes, on the other hand, have a Text property, that is whatever is entered into the text box. So if you type "hello" into a text box named Text1, its Text property (referred to as Text1.Text) equals "hello".


The Intro to Visual Basic homepage is hosted by GeoCities
1