Platinum Edition Using Visual Basic 5

Previous chapterNext chapterContents


- 4 -
Working with Forms and Controls

Forms provide the foundation of a program's user interface. Forms act as containers for the various controls with which the user will interact.
Controls are the objects that the user actually interacts with. Learn how to create instances of a variety of types of controls on your forms.
Learn how to use properties, methods, and events of forms and controls to customize how your program looks and works.
Find out how to set the properties of multiple controls as a group and how to use the Form Editor toolbar to work with multiple controls.
See how the controls on a particular form are contained in a collection and how you can use program code to manipulate all the controls easily.

Visual Basic program can be broken up into two main components: the visual component and the code component. The code component refers to the program code that you type in, which the user never sees on-screen. The visual component, or user interface, is created by using forms and controls. The forms and controls allow you to handle user input, information display, and user decisions. The nature of Visual Basic's design also allows you to extend the program's capabilities through the use of third-party controls and add-ins. In this chapter, you'll learn the standard techniques for using forms and controls.

Exploring Properties

While forms and controls are typically thought of as just what the user sees on the screen, their appearance and behavior are controlled by three basic elements: properties, methods, and events. This section explains these elements in terms of how they define a form, but the principles discussed here apply to all controls that you might use in Visual Basic.

See "Handling Events in Your Programs," Chapter 7

When you look at a form, you see a rectangular window on the screen, like the one shown in Figure 4.1. But in reality, this window is defined by a series of properties. For example, the position of the form on the screen is controlled by the Left and Top properties, while the form's size is controlled by its Height and Width properties. The form title that you see in the title bar displays the contents of the form's Caption property. By setting properties, you can even determine which control buttons appear on the form.

FIG. 4.1
The basic elements of a form are defined by its properties.

You can use a text editor such as Notepad to open the .FRM file that is created for each of your forms. This text file stores the form's property settings as well as the event code. Figure 4.2 shows a portion of an .FRM file.

FIG. 4.2
The properties of a form are stored in text format in an .FRM file.


CAUTION: For most forms, Visual Basic also creates a file with an .FRX extension. This file stores graphics and other binary elements that cannot be defined by text. It is important when moving forms to another subdirectory to copy the .FRX files as well.

You can think of the properties of a form or control as descriptions of the object's characteristics. This is similar to describing a person. For example, how would you describe yourself? You would probably cite such characteristics as height, weight, hair color, and eye color. Each element of your description could be considered a property.


NOTE: The term "object" in this chapter refers to visual objects such as forms and custom controls. In later chapters we will further discuss objects and object-type variables, and how they relate to Visual Basic program code.

What Properties Do Most Objects Have in Common?

All objects in Visual Basic do not have the same set of properties. However, there are several properties that are common to most objects. Some important, common properties are:

Controlling Form Size

You can control a form's size by selecting it and dragging its sizing handles at design time, or by changing the values of its Height and Width properties at either design time or runtime. If you do this at design time, you will see a corresponding change in the Height and Width properties in the Properties window. During program execution, you can use code to respond to or initiate a change in size. Try it now:

1. Create a new Standard EXE project and press F5 to run it.

2. Press Ctrl+Break (or click the Break button) to enter Break mode.

3. Press Ctrl+G to bring up the Immediate window.

4. In the Immediate window, type Print Form1.Width and press Enter. (The Immediate window, formerly known as the Debug window, enables you to type and execute program statements while in Break mode.) The current value of the Width property is printed (see Figure 4.3).

FIG. 4.3
You can print many properties of a form, such as the Width property, in the Immediate window.

5. In the Immediate window, type form1.Width = form1.Width * 2 and press Enter.

6. Press F5 (or click the Start button), and notice that Form1's width has doubled (see Figure 4.4).

FIG. 4.4
Setting a new value for the Width property in the Immediate window causes the form's width to change immediately.

You can see the value of the new width by returning to Break mode and again entering Print Form1.Width in the Immediate window.


Measurements in Visual Basic 5
By default, all distances are measured in twips. A twip is a unit of measure for objects. The actual physical size of a twip varies depending on screen resolution. You can specify another unit of measure for objects within a container using the container's ScaleMode property. However, the screen's scale mode cannot be changed, so a form's Left, Top, Height, and Width properties are always measured in twips.

Adjusting Form Position

In addition to controlling a form's size, you can control its position with the Left and Top properties (see Figure 4.5). The Left property specifies the distance of the left side of the object from the left side of the object's container. The Top property specifies the distance of the top edge of the object from the top of its container. In the case of a standard form, the container is the entire screen. If you draw a control on a form, the form is the control's container. It is also necessary to mention that some controls themselves, such as PictureBox and Frame controls, can act as containers for other controls.

FIG. 4.5
This TextBox's position is measured relative to the form.


NOTE: An object's Top and Left properties can actually have a negative value! For example, a Label control whose Left property value is -1440 would be positioned so that its left edge is approximately one inch to the left of its container; therefore, some or all of it would not be seen.

While the position of most forms is measured in relation to the upper-left corner of the screen, a form that is part of a Multiple Document Interface (MDI) or browser application is positioned relative to the upper-left corner of the client area (see Figure 4.6).

Controlling User Interaction

Even if your application includes many forms and controls, you probably do not want the user to have access to all of them at the same time. For example, suppose you are writing a word processor. You might have Save File and Load File buttons, but you would not want the user to press Save File until after a file has been loaded. Two properties, the Visible property and the Enabled property, allow you to manage this process.

The Visible property determines if an object can be seen on the screen. The Enabled property determines whether the user can interact with an object. Both properties can be set to either True or False.

FIG. 4.6
MDI child forms and ActiveX documents are positioned relative to the parent form.

If the Visible property is set to False, the object is not shown, and the user will not know that the object is even there. If the Enabled property is set to False, the object is visible (provided that the Visible property is True), but the user cannot interact with it. Typically, if an object is disabled, it is shown on the screen in a grayed-out, or dimmed, mode. This provides a visual indication that the object is unavailable.

A good example of objects that are variably available and unavailable occurs in the wizard interface in some Windows programs. A Wizard organizes a task into several logical steps, with three navigation buttons (typically labeled Back, Next, and Finish) that are used to move between steps. Depending on which step the user is currently working on, all of these buttons may not be enabled, as in Figure 4.7.

FIG. 4.7
Because the user is on step 1 of 4, the Enabled property of the Back button is set to False, causing it to be grayed out.


TIP: If you are implementing a wizard interface in Visual Basic, one option is to draw the controls for each step in a frame. The Visual Basic Frame control acts as a container, so setting its own Visible property relevant to the user's current step affects all the controls within it. For more information, see Chapter 13, "Using Containers."

Referencing Forms and Controls from Your Code

One other key property of every Visual Basic object is the Name property. The Name property defines a unique identifier by which you can refer to the object in code. Each form, text box, label, and so on must have a unique name.


NOTE: All forms in a project must have different names. However, control names have to be unique only for the form on which they are located. That is, you can have a "Text1" control on each form in your project, but you can't have two "Form1" forms in your project.

Visual Basic provides a default name when an object is first created. For example, Form1 is the name given to the first form created for your project, and Text1 is the name given to the first text box that you place on a form. However, the first thing you should do after drawing a control or form is to provide it with a name that has some meaning. For example, I always use frmMain as the name of the main interface form in my applications.

As you are naming your objects, it's good programming practice to use the first three characters of the object's name as a prefix to identify the type of object to which the name refers. As in the frmMain form that we just discussed, the prefix frm indicates that the object is a form. Table 4.1 lists suggested prefixes for many of Visual Basic's objects (forms and controls).

Table 4.1 Prefixes that Identify the Object Type

Object Type Prefix Object Type Prefix
CheckBox chk Horizontal ScrollBar hsb
ComboBox cbo Image img
Command Button cmd Label lbl
Common Dialog cdl Line lin
Data Control dat ListBox lst
Data Bound ComboBox dbc Menu mnu
Data Bound Grid dbg OLE Container ole
Data Bound ListBox dbl Option Button opt
Directory ListBox dir Picture Box pic
Drive ListBox drv Shape shp
File ListBox fil TextBox txt
Form frm Timer tmr
Frame fra Vertical ScrollBar vsb
Grid grd

Remember that the names you assign will be used in code, so avoid carpal tunnel syndrome by keeping them short!

To set the ame property for an object, select the object, view the Properties window (by clicking the Properties button, by selecting View, Properties Window, or by pressing the F4 key), and click the Name property. You can then type a new value.

FIG. 4.8
The Name property is located at the top of the list on the Alphabetic page and is the first property listed under the Misc group on the Categorized page.


TIP: To quickly go to a specific property while in the Properties window, hold down the Ctrl and Shift keys and press the first letter of the property name. This takes you to the first property starting with that letter. Additional key presses take you to the next property with the same letter.

A First Look at Methods and Events

So far in this chapter, we have concentrated on properties, showing how they can control an object's appearance. However, forms and controls in Visual Basic are not just idle components that sit and look pretty. In addition to properties, an object can have methods, which define tasks that it can perform. The tasks can be simple, such as moving the object to another location, or they can be more complex, such as updating information in a database.

Taking Action with Methods

A method is really just a program function that is built into the object. Using its embedded methods, the object knows how to perform the task; you don't have to provide any additional instructions. For example, forms have a PrintForm method that prints them to the current printer. The statement Form1.PrintForm prints an exact duplicate of Form1. Because the low-level details for the PrintForm method are encapsulated within the form object, a Visual Basic programmer does not have to be concerned with them.

As you may have guessed, methods, like properties, use dot notation. When typing code, Visual Basic uses the Auto List Member feature to list an object's methods and properties when you type the object's name followed by a period.While there are different methods for different objects, many objects have the following methods in common:


NOTE: Focus refers to the current control that receives user actions, such as keystrokes. Only one control on any form can have the focus at any given time. Focus is usually indicated by the position of the edit cursor (for text boxes) or a dotted rectangle around the control (for check boxes, option buttons, and command buttons).

Responding to Actions with Events

In addition to performing tasks, the objects in your program can respond to actions, whether generated by the user or externally. These actions are handled through the use of events. For example, when a user clicks a command button, he causes a Click event to occur to that command button. Part of the definition of an object determines to which events it responds.

Examples of events are clicking a command button, selecting an item in a list box, or changing the contents of a text box. Events also occur when the user exits a form or switches to another form. When an event happens to an object, the object executes an event procedure for that specific event. To respond to events, you have to place program code in the object's event procedures. For example, in Chapter 3 you placed code in the Click event of a command button for the Loan Calculator program.

See "Performing Tasks," Chapter 3

Chapter 7, "Responding to the User," delves into all the intricacies of events. In that chapter, you learn how to write code to handle events and how multiple events are related.

See "Handling Events in Your Programs," Chapter 7

How Properties and Methods Are Related

By now, you know that objects have properties to define their appearance, methods that let them perform tasks, and events that let them respond to user actions. You might think that all these things happen independently of one another, but that is not always the case. Sometimes, the properties and methods of an object are related. That is, as you invoke a method of an object, the properties of the object are changed. Also, most times that you use the methods of an object or change its properties with code, you do so in response to an event.


NOTE: Some property changes can trigger events. For example, changing the Height or Width property of a form in code triggers the form's Resize event.

You can see one example of the interdependence of methods and properties of an object when the Move method is used and the Left and Top properties are set. You can cause an object to change position either by using the Move method or by setting the Left and Top properties to ew values. For example, the following two code segments accomplish the same task of changing a text box control's position to 100 twips from the left and 200 twips from the top of its container:

`CODE SEGMENT 1 - Move the text box by setting its properties
txtName.Left = 100
`CODE SEGMENT 2 - Move the text box using the Move method
txtName.Move 100, 200

You should otice two things about these code segments. First, code lines beginning with a single quote (') are considered comments; that is, Visual Basic ignores anything after the single quote. You can use comments to describe or explain your code. Second, if you type the code segments, you'll notice that the Move method has two additional arguments available. These optional arguments can change the size of the object. This has the same effect as setting the Height and Width properties to new values.

Similarly, the Show and Hide methods of a form have the same effect as changing the form's Visible property. When you invoke the form's Hide method, the effect is the same as setting its Visible property to False. (The effect, of course, is that the form disappears from the screen.) Likewise, the form's Show method produces the same effect as setting its Visible property to True.

Forms

So far, most of our examples have used the Form object. A form is a container that holds all the other controls (such as labels, text boxes, and pictures) that make up the user interface. Most of your programs will use a number of forms.


NOTE: It is possible to create a Visual Basic program that contains no forms at all! One example might be a command-line program that processes files and requires no user interface.

Parts of a Form

When you start a new Standard EXE project, you are presented with the default project, which normally includes a single standard form (see Figure 4.9). Because this form is where you start work on your user interface, let's take a look at the different parts of it.

FIG. 4.9
A form is the starting point for building a user interface.

As you can see in Figure 4.9, a Visual Basic form contains all the elements you would expect to find as part of a window in a program. It contains a title bar, a control menu, and a set of Minimize, Maximize/Restore, and Close buttons. Note that many of these elements, such as the Close button, are always present at design time even if the properties are set in such a way that they are not visible at runtime.

Another design-time feature is a grid that allows you to easily line up controls as you are designing your interface. You can control the behavior of the design grid through the Options dialog box, accessible by choosing Tools, Options. In this dialog box, you can change the size of the grid or even turn it off completely. You can also choose whether or not controls are automatically aligned to the grid. If this option is on (the default setting), the upper-left corner of each control is aligned with the grid point that's closest to the corner. Using the default setting makes it easy to line up controls. In fact, I set the grid to be smaller than the default, which allows more precise control alignment.

Form Properties Revisited

Forms, like most of the objects used in Visual Basic, have a series of properties that control their behavior and appearance. In the earlier section "Controlling User Interaction," you learned about some of the properties that apply to forms. In this section, you learn about several additional key properties of forms. You also learn how these properties can be controlled during program design and execution. Table 4.2 lists several of the key properties of a form and provides a brief description of each. The table also identifies whether the value of the property can be changed while the program is running.

Table 4.2 Key Properties for Controlling a Form

Property Name Description Changeable
at Run Time
BorderStyle Sets the type of border that is used for the form No
ControlBox Determines whether the control box (containing the Move and Close menus) is visible when the program is running No
Font Determines the font used to display text on the form Yes
Icon Determines the icon that is shown in the form's title bar and that appears when the form is minimized Yes
MaxButton Determines whether the Maximize button is displayed on the form when the program is running No
MDIChild Determines whether the form is a child form for an MDI application No
MinButton Determines whether the Minimize button is displayed on the form when the program is running No
StartUp Position Determines the initial position of a form when it is first shown Yes
WindowState Determines whether the form is shown maximized, minimized, or in its normal state Yes

Now let's take a closer look at some of these properties. The BorderStyle property has six possible settings that control the type of border displayed for the form (see Table 4.3). These settings control whether the form is sizable by clicking and dragging the border; they control the buttons that are shown on the form; and they even control the height of the form's title bar (see Figure 4.10).

FIG. 4.10
Changing the BorderStyle property can give a form many different appearances.

Table 4.3 Possible BorderStyle Property Settings that Control the Type of Window Displayed

Setting Effect
0 - None No border is displayed for the form. The form also does not display the title bar or any control buttons.
1 - Fixed Single A single-line border is used. The title bar and control buttons are displayed for the form. The form is not resizable by the user.
2 - Sizable border The border appearance indicates that the form can be resized. The title bar and control buttons are displayed. The form can be resized by the user by clicking and dragging the border. This is the default setting.
3 - Fixed Dialog The form shows a fixed border. The title bar, control box, and Close button are shown on the form. Minimize and Maximize buttons are not displayed. The form cannot be resized.
4 - Fixed ToolWindow The form has a single-line border and displays only the title bar and Close button. These are shown in a reduced font size (approximately half height).
5 - Sizable ToolWindow This is the same as the Fixed ToolWindow, except that the form has a sizable border.


NOTE: Setting the BorderStyle property to prevent resizing does not affect the form's appearance in the design environment; it affects it only at run time.

The default setting provides a border that enables the user to resize the form while the program is running. This is the type of form that you find in most of the programs you use, such as Microsoft Word or Microsoft Money. However, you can change the BorderStyle setting to make the form look like almost any type of window that you would see in a program, including toolboxes and dialog boxes. You can even remove the form's border altogether.

In Table 4.3, several of the BorderStyle definitions indicate that a control box and the Close, Minimize, and Maximize buttons would be displayed in the title bar of the form. This is the default behavior. But even with these border styles, you can individually control whether these elements appear on the form. The ControlBox, MaxButton, and MinButton properties each have a True or False setting that determines whether the particular element appears on the form. The default setting for each of these properties is True. If you set a property to False, the corresponding element is not displayed on the form. These properties can be changed only at design time.

The Font property lets you set the base font and font characteristics for any text displayed directly on the form by using the form's Print method.


NOTE: The Font property of a form is actually an object itself with its own properties. For example, to change the size of a form's font, you would enter Form1.Font.Size = 10 in a Code window (or the Immediate window, for that matter) to change the size to 10 points.

In addition, setting the form's Font property sets the font for all controls subsequently added to the form.


TROUBLESHOOTING: I set the Font property of the form, but the font in the title of the form did not change. The Font property of the form has no effect on the form's title; it affects only on its internal area. Windows itself controls the font for a window title. This can be changed in the Windows 95 Control Panel.

When I use a form's Print method, sometimes I can't see my text. If you do not set the form's AutoRedraw property to True or use the Refresh method, your text can be erased when another window is stacked on top of the form. Also, you need to look at the CurrentX and CurrentY properties to make sure that the text is displayed within the visible area of the form.


One final form property of note is the StartupPosition property. As you might guess, this property controls where the form is located when it is first displayed. There are four possible settings for the StartupPosition property. These settings are summarized in Table 4.4.

Table 4.4 Possible StartupPosition Property Settings that Control Where the Form Is Initially Displayed

Setting Effect
0 - Manual The initial position is set by the Top and Left properties of the form.
1 - CenterOwner The form is centered in the Windows desktop unless it is an MDI child form, in which case it is centered within its parent window.
2 - CenterScreen The form is centered in the Windows desktop.
3 - Windows Default The form is placed in a position determined by Windows based upon the number and position of other windows open at that time.


NOTE: This feature is a godsend to longtime Visual Basic programmers. In previous versions of Visual Basic, you had to write code to center the form by setting the Top and Left properties or by using the Move method. With the StartupPosition property, this is all handled for you.

Although the StartupPosition property can center your form for you when the form first loads, it does not keep the form centered. For example, if you resize the form, it does not remain centered. If you want to have the form centered after it has been resized, you still need to write code to perform the task. This code (see Listing 4.1) should be placed in the form's Resize event procedure.

Listing 4.1 FORMDEMO.FRM--Using Code to Keep a Form Centered After Its Size Is Changed

If Me.Height >= Screen.Height Then
    Me.Top = 0
Else
    Me.Top = (Screen.Height - Me.Height) / 2
End If
If Me.Width >= Screen.Width Then
    Me.Left = 0
Else
    Me.Left = (Screen.Width - Me.Width) / 2
End If

Note in the preceding listing the use of the Me keyword, instead of the form name (such as Form1). When used in a form's code, Me represents the form itself without having to refer to it by name, much as a pronoun can refer to a person without having to use his or her name. This means that the same block of code could be inserted into several forms without any changes. Also, if a form is ever renamed, Me ensures that the changed name doesn't affect procedures that act upon the form.


TIP: Visual Basic's new Form Layout window is useful if you are working in a higher resolution than that in which your users will be running your program. Right-click the Window and check the Resolution Guides option to see form sizes relative to standard screen resolutions.

Displaying a Form

If you write a program with just a single form, you needn't worry about displaying the form or hiding it. This is done automatically for you as the program starts and exits. This single form is known as the Startup Object or Startup Form. When you run your program, Visual Basic loads your Startup form into memory and displays it. As long as this form remains loaded, your program keeps running and responding to events. When you press the Close button on the form (or execute the End statement), the program stops.


NOTE: You can select a Startup form in the Project Properties dialog box. It is also possible to have a program start from a Sub procedure named Main in a code module rather than from a form.

However, if you have multiple forms--as most of your programs do--you need to understand how to manage them. The state of a form is controlled by Visual Basic's Load and Unload statements, as well as the form's Show and Hide methods.

The Load statement places a form in memory, but does not display it. The following line of code shows how the statement is used:

Load frmMember

By using this, you are explicitly loading the form. However, the form is loaded automatically if you access a property, method, or control on it.

Because the load operation is performed automatically, it is not really necessary to use the Load statement with a form. However, it is important to be aware when a form is being loaded, because the code in the Form_Load event will be executed at that time.


TIP: There are some cases where you would want to use the Load statement (see the "Using Load to Enhance Performance" sidebar later in this section).

To display the form, you must use the Show method. The Show method works, whether or not the form was loaded previously into memory. If the form was not loaded, the Show method implicitly loads the form and then displays it. The Show method is used as follows:

frmMember.Show

The Show method also has an optional argument that determines whether the form is shown as a modal or modeless form. If a form is shown modally, then no other forms or code outside that form are executed until the modal form is closed. Think of the program code as being paused as long as a modal form is displayed. An example of a modal form is the Windows 95 Shut Down screen. You cannot put the focus on another window while the Shut Down Windows form is displayed.

If a form is shown modeless, you can move at will between the current form and other forms in the program. The preceding statement displayed a form as modeless. To create a modal form, you simply set the optional argument of the Show method to vbModal, as shown here:

frmMember.Show vbModal


NOTE: A modal form is typically used when you want the user to complete the actions on the form before working on any other part of the program. For example, if a critical error occurs, you do not want the user to switch to another form and ignore it.

After a form is displayed, you have two choices for getting rid of it. The Hide method removes the form from the screen but does not remove it from memory. Use Hide when you need to temporarily remove the form from view but still need information in it, as in the following code example:

frmSelect.Show vbModal
frmResults.Print "The date you entered was: " & frmSelect.txtDate

In the preceding example, the purpose is to display a form and then retrieve a value from a text box on it. Because the form is shown modally, the second statement is not executed until the form is removed from the screen. Presumably, the user would enter the information and then press a button that executed frmSelect's Hide method.

If you are finished with a form and the information contained on it, you can remove it from both the screen and memory with the Unload statement. The Unload statement uses basically the same syntax as the Load statement, as shown here:

Unload frmMember


TIP: If you are using the Unload statement from within the form you are removing, you can use the keyword Me to specify the form. This prevents errors if you later rename your form. In this case, the statement would be the following:
Unload Me


Using Load to Enhance Performance
Because the Show method automatically loads a form into memory, it typically is not necessary to use the Load statement in your program at all. However, some forms with a very large number of controls display slowly when they are shown. One way around this is to load the form into memory, by using the Load statement, when the program begins to run. With the form already in memory, subsequent Hide and Show methods appear to perform much more quickly. If you use this trick, be careful of two things. First, don't forget to unload the form at the end of your program. Second, be aware of possible memory limitations. If you load too many forms in memory at once, you might see a decline in the overall performance of your program.

Loading forms into memory does increase the amount of time that it takes for your program to start, but you will save time whenever the form is shown. If you show a form only once during the program, there is no net time savings by loading it at the beginning. However, if the form is shown more than once, there usually is an overall time savings. Also, users are typically more tolerant of time delays when a program loads (especially if they're busy looking at a splash screen) than later when they are performing a task.


Handling Events

In the section "Responding to Actions with Events," you learned that most objects respond to events or actions that are taken by a user, the program, or the operating system. There are five special events that occur to each form, and you can place code in the associated event procedure for any of these:

The key to understanding the purposes of these events is knowing when they occur. If you still are confused, try the simple tutorial that follows.

First, follow these steps to set up a test project:

1. Open Visual Basic and create a new Standard EXE project.

2. Double-click the center of Form1 to bring up its Code window.

3. Make sure the Load event is selected in the drop-down Event box at the upper-right of the Code window.

4. Type the statement MsgBox "Form Load Event" into the event procedure so that the code looks like this:
Private Sub Form_Load()
    MsgBox "Form Load Event"
End Sub
5. Repeat Steps 3-4 to place similar MsgBox statements in the Initialize and Unload events.

6. Add a second form, Form2, to the project by choosing Project, Add Form.

Now that you have created the project, press F5 to run it. Notice that the Initialize event comes first, followed by the Load event. Click the form's Close button, and you will notice that the Unload event occurs before the program stops.

Now start the program again and then press Ctrl+Break to pause execution. Press Ctrl+G to bring up the Immediate window. Put the cursor in the Immediate window and enter these lines (pressing Enter after each), observing the messages that appear:

Load Form2
Unload Form1
Load Form1

(The reason you load Form2 is to prevent the program from ending when you unload Form1.) You should have noticed that the Initialize event did not occur when Form1 was loaded the second time. Enter the following lines:

Unload Form1
set Form1 = Nothing

It's good practice to set an instance of a form to Nothing when you're done with it. This ensures that all resources that were allocated to the form are properly released.

Now enter this line:

Load Form1

You'll see that the Initialize event occurs again. This is because the instance of Form1 that you created before was destroyed when it was set to Nothing.

You can use program code in these events to set the properties of the form or any of its controls, set up databases or recordsets needed for the form, or run any other code that you might find necessary. The Load and Unload events each occur only once in the life of a form--when the form is loaded and unloaded from memory, respectively. On the other hand, the Activate and Deactivate events can occur many times. Therefore, you need to be careful of which code is placed in which event.

The following code segments show you a couple of simple but useful things that you can do with code in the Load event procedure. Listing 4.2 shows you how the captions of labels and command buttons can be set by using the LoadResString function to read a string from a resource file. This is useful when you want to be able to distribute your application in multiple languages, as you need only replace the resource file with one created in the appropriate language.

Listing 4.2 RESOURCE.FRM--Using Load to Set Captions

`Retrieve the captions for all controls from resource file
 `Caption range is 701 to 750
Me.Caption = LoadResString(701)
For I = 0 To 5
    cmdSearch(I).Caption = LoadResString(702 + I)
Next I
fraSearch.Caption = LoadResString(708)
For I = 0 To 4
    lblSearch(I).Caption = LoadResString(709 + I)
Next I
For I = 0 To 1
    cmdTitle(I).Caption = LoadResString(714 + I)
Next I
fraChngTitle.Caption = LoadResString(716)
For I = 0 To 1
    lblTitle(I).Caption = LoadResString(717 + I)
Next I
cmdDone.Caption = LoadResString(719)

Another use of the Load event is to open recordsets in a database application. This enables you to open the recordset once and then use it throughout the code in the form. This is shown in the following code:

Set ConvSet = MemDb.OpenRecordset("Conventions", dbOpenTable)
ConvSet.Index = "Convention"
ConvSet.MoveLast
LastRec = ConvSet("ConvID")

It's often also useful to maximize the form as it is displayed. This involves simply setting the WindowState property of the form when the form is loaded. This is done as follows:

Me.WindowState = vbMaximized

Another form event that you will use often is the Resize event. This event is triggered any time the size of the form is changed, either by the user or by your program. It also occurs after the form's Load event, before the Activate event occurs. Typically, you use the Resize event to change the size of one or more controls on your form. Doing this gives the user more room to work when the size of the form is increased and prevents information from being hidden when the size of the form is decreased. Listing 4.3 shows how the size of a data-bound Grid control changes when the form's size is changed. The code also checks the WindowState property of the form and does not perform the operation when the form is minimized.

Listing 4.3 RESIZE.FRM--Changing the Size and Position of Controls when the Form Size Changes

If Me.WindowState <> vbMinimized And AllowResize Then
    dbgResults.Width = Me.ScaleWidth - 180
    dbgResults.Height = Me.ScaleHeight - dbgResults.Top - 60
End If

Using Controls

Although forms are an important part of your programs, you can't do very much without adding controls to them. Visual Basic controls let you do a wide variety of things including edit text, display pictures, and interface with a database. The liberal use of controls has always been one of Visual Basic's strongest features. Because of Visual Basic's design, you are not limited to using only the controls provided by Microsoft. The design allows easy integration of third-party controls--which has led to a thriving market for these custom controls. With this amount of third-party involvement, chances are that you can find a control to perform almost any task you want, from data acquisition to custom reporting to specialized graphics processing to game play, and everything in between. While controls have been around since the beginning of Visual Basic, the capability to create your own controls was just introduced in version 5. Visual Basic now allows you to create your own ActiveX controls for use in your programs and in any other program that adheres to ActiveX standards.

What Are Controls?

Controls are objects in Visual Basic designed to perform specific tasks. Like form objects, controls have associated properties, events, and methods. For example, if you use a TextBox control, you can set properties to determine the size of the text box, the font for the text that it displays, and the color of the text and background. The text box correctly sizes and displays the text, based on the property values that you assign. Also, a text box has internal code that allows it to process keystrokes, so that it knows, for example, to erase a character when you press the Backspace key. If you wrote programs in earlier languages, particularly in the DOS and mainframe environments, you know that you might have had to write a significant amount of code just to accept and process keystrokes that allowed the user to enter input. Now you just drop a control on your form, and the rest is done for you.

Visual Basic 5 comes with a standard set of controls that are available in all editions and that let you perform many types of programming tasks. These controls are illustrated in the Toolbox shown in Figure 4.11 and are listed along with their functions in Table 4.5. Many of these controls are discussed in detail in the later section "Finding Out What Controls Can Do."

FIG. 4.11
The Visual Basic controls are accessible from this Toolbox.

Table 4.5 Visual Basic 5 Standard Set of Controls

Control Button

Control Name Function

PictureBox Displays graphics. Can also serve as a container for other controls.

Label Displays text that the user cannot edit.

TextBox Displays text; enables the user to enter and edit the text.

Frame Serves as a container for other controls. Provides grouping of controls.

CommandButton Enables the user to initiate actions by clicking the button.

CheckBox Lets the user make a true/false choice.

OptionButton Lets the user choose one option from a group of items.

ComboBox Lets the user choose from a list of items or enter a new value.

ListBox Lets the user choose from a list of items.

Horizontal ScrollBar Lets the user choose a value based on the position of the button in the bar.

Vertical ScrollBar Same as Horizontal ScrollBar.

Timer Lets the program perform functions on a timed basis.

Drive List Box Lets the user select a disk drive.

Directory List Box Lets the user select a directory or folder.

File List Box Lets the user select a file.

Shape Displays a shape on the form.

Line Displays a line on the form.

Image Similar to a PictureBox control. Uses fewer system resources, but doesn't support as many properties, events, and methods.

Data Control Provides an interface between the program and a data source.

OLE Provides a connection between the program and an OLE server.

Common Dialog Enables use of Windows standard dialog boxes to retrieve information such as file names, fonts, and colors.


NOTE: The controls shown in the preceding figure and table are not the only ones included with Visual Basic. To add other controls, such as the Microsoft Common Dialog Control or Microsoft FlexGrid control, to your Toolbox, use the Components dialog box by choosing Components from the Project menu.

Adding Controls to the Form

To be able to use any of the available controls, you must first add them to a form. To add a control, simply select the appropriate tool in the Toolbox, then draw the control on the form by clicking the form and dragging the mouse. You can also double-click the tool to add a default-sized control to the center of the current form. After the control is on the form, you can set its properties and use it in your program.

Setting and Retrieving Control Property Values

One way to set property values is by using the Properties dialog box at design time. However, for the controls to be really useful in your programs, you need to be able to set their properties in code as the program runs and, more importantly, to retrieve the values of their properties. For example, you know that a user can enter text in a TextBox control, but to be able to use the text he or she entered, you need to be able to read it from the control. For example, you may want to read a user's input and convert it to uppercase letters before further processing.

When you are using a control's property in code, you can use it just like you would a variable or constant. You can use the properties in comparison statements to make decisions, and you can use them in assignment statements to set the value of a variable. You can also use an assignment statement to set the value of a property. The following code shows how the Text property of a text box is used to retrieve a name entered by the user, convert it to all capitals, and put the modified text back in the text box:

Sub cmdCapitalize_Click()
  Dim sName As String
  sName = txtName.Text
  sName = Ucase$(sName)
  txtName.Text = sName
End Sub

To reference an object's property in code, you must specify the name of the object (the text box named txtName in the preceding code) and the name of the property (the Text property in this example), using a dot (or period) to separate them. Be aware, however, that some properties are read-only at run time, and some only exist at run time. An object can have more properties than those listed in the Properties window. To find a complete list, look up the control in the Help system and follow the Properties hyperlink.


NOTE: If you are referring to a control on a form other than the current form, you also need to specify the name of the form. The form name precedes the control name and is separated from it by a dot (.). A generalized syntax for changing property values that always works is formname.objectname.propertyname = value. For example:
frmMember.txtName.Text = "Smith, John" 

It is good programming practice to always specify the name of the property, but many controls have what is known as a default property. A default property can be referenced simply by specifying the name of the control. For example, the Text property is the default property of the TextBox control. Therefore, the following two statements work exactly the same:

`*************************************
`Property name specifically referenced
`*************************************
txtName.Text = "Mike"

`*************************************************
`Property name omitted, utilizing default property
`*************************************************
txtName = "Mike"

Table 4.6 shows the default property of a number of controls.

Table 4.6 Default Properties of Common Controls

Control Type Value Property
Check box Value
Combo box Text
Directory list box Path
Drive list box Drive
File list box FileName
Horizontal scroll bar Value
Image Picture
Label Caption
Option button Value
Picture box Picture
Text box Text
Vertical scroll bar Value

Finding Out What Controls Can Do

In the previous sections, you learned what controls are and how to use them in your programs. You also learned a little about their properties, methods, and events. In this section, you find out more details about some of the most frequently used controls. You learn about other controls in Part II, "Visual Basic Controls."

Working with Text

One of the most common tasks in programming is working with text. Now, text here does not just mean paragraphs and sentences like those you handle with a word processor. When you deal with text in a program, you also might want to display or retrieve a single word, a number, or even a date. For example, in a data-entry program, you might need to handle the name, address, telephone number, date of birth, and other information about a member. Text information can easily be handled using Visual Basic's TextBox control. Figure 4.12 shows a data-entry screen for a membership application.

Visual Basic provides several controls for handling text. The major controls included with VB are the Label, TextBox, Masked Edit, and RichTextBox controls. These controls can handle most of your program's text editing and display needs.

FIG. 4.12
You can handle all types of information with text controls.


NOTE: In this chapter, only the Label and TextBox controls are covered. The RichTextBox and Masked Edit controls are covered in detail in Chapter 14, "Working with Text, Fonts, and Colors."

Using a Label Control to Display Text The simplest control that displays text is the Label control. The most common use of the Label control is identifying different items on a form, such as the data-entry form shown in Figure 4.12. Each label identifies the information in the edit field next to it. Used in this way, each label typically is set up at design time, and the necessary text is assigned to the label's Caption property in the Properties dialog box. However, you are not limited to using the Label control in this manner. In fact, you can use the Label control to display any type of information to the user. A label can display a date, a number, a single word, or even an entire paragraph of information.

While the Caption property of the Label control contains the text to be displayed, there are other properties of the control that influence how the text is displayed. The most obvious of these properties are the Font and ForeColor properties, which determine the typeface and text color of the control, respectively. However, if you are going to use the label to display more than a small amount of text, the AutoSize and WordWrap properties are the ones that will be most important to you.

If you know in advance what text is going to be displayed in a label's Caption property, you can set the size of the label to accommodate the text. However, if different text will be displayed in the label at different times (for instance, in a database application), it needs to be able to adjust to the length of its current contents. The AutoSize property of the Label control determines whether or not the size of the control automatically adjusts to fit the text being displayed. When AutoSize is False (the default), the label's size remains unchanged regardless of the length of its caption. If a caption is too long for the label, some of it will not be visible.

Setting AutoSize to True causes a label to automatically adjust its size to fit its caption. If the caption is longer than the label's original size allows, the method of resizing depends upon the value of the WordWrap property. If the WordWrap property is False (the default), the label expands horizontally to allow the caption to fit, even if the label grows so large that it runs past the right edge of the screen. If the WordWrap property is set to True, the label expands vertically to allow enough lines of text to accommodate the caption, even if the label runs off the bottom edge of the screen. (The words wrap to new lines, hence the property name WordWrap.) In either case, the Caption property contains the entire caption, even if some of the text "spills off" of the form. The effects of the different settings of the AutoSize and WordWrap properties are shown in Figure 4.13.

FIG. 4.13
These four labels have the same long caption; their AutoSize and WordWrap properties determine if and how they resize to fit the caption.


TIP: When assigning a label's Caption property, you can force a new line by including a carriage return and line feed combination. This technique is a throwback to the ancient days of manual typewriters. When a manual typewriter user reached the end of a line, he had to manually move the paper up to the next line (a line feed) and return the carriage to the beginning of that line (a carriage return). In Visual Basic, you can insert a carriage return/line feed combination by inserting ASCII characters 13 and 10 into the caption at the point where the line should break. Visual Basic supplies a predefined constant, vbCrLf, to help you accomplish this task:

Label1.caption = "First Line" & vbCrLf & "Second Line"






CAUTION: To preserve the original width of your Label control, you must set the WordWrap property to True before setting the AutoSize property. Otherwise, when you set the AutoSize property to True, the Label control adjusts horizontally to fit the current contents of the Caption property.

There are three other properties that, from time to time, you might need to use with the Label control. These are the Alignment property, the Appearance property, and the BorderStyle property. The Alignment property determines how the text is aligned within the Label control. The possible options are Left-Justified, Right-Justified, and Centered. The Appearance can be set to Flat or 3-D to govern whether the label appears raised from the form. The BorderStyle property determines whether the Label control has no border or a single-line border around the label. With BorderStyle set to Fixed Single, the Label control takes on the appearance of a noneditable text box. The effects of the Alignment, Appearance, and BorderStyle properties are shown in Figure 4.14.

FIG. 4.14
The Alignment, Appearance, and BorderStyle properties can change the look of a Label control.


NOTE: The Alignment property also affects the text when the label is used to display multiple lines. The control aligns each line according to the setting of the Alignment property (refer to Figure 4.14).

Entering Text with a Text Box Because much of what programs do is to retrieve, process, and display text, you might guess (and you would be correct) that the major workhorse of many programs is the TextBox control. The text box enables you to display text; more importantly, however, it also provides an easy way for your users to enter and edit text and for your program to retrieve the information that was entered. In most cases, you use the text box to handle a single piece of information, such as a name or address. But the text box is capable of handling thousands of characters of text. A TextBox control's contents are stored in its Text property--the main property with which your programs will interact. You can also limit the number of characters a user can enter with the MaxLength property.

By default, the text box is set up to handle a single line of information. This is adequate for most purposes, but occasionally your program needs to handle a larger amount of text. The text box has two properties that are useful for handling larger amounts of text--the MultiLine and ScrollBar properties.

The MultiLine property determines whether the information in a text box is displayed on a single line or multiple lines. If the MultiLine property is set to True, information is displayed on multiple lines, and word-wrapping is handled automatically. The user can press Enter to force a new line. The ScrollBar property determines whether or not scroll bars are displayed in a text box, and if so, what type of scroll bars (None, Horizontal, Vertical, or Both). The scroll bars are useful if more text is stored in the Text property than fits in the text box. The ScrollBar property has an effect on the text box only if its MultiLine property is set to True. Figure 4.15 shows the effects of the MultiLine and ScrollBar properties.

FIG. 4.15
You can use a text box to enter single lines of text or entire paragraphs.


TROUBLESHOOTING: The text box in my program will handle only about 32,000 characters instead of the 64,000 specified in the documentation. When you use the default value of zero for the MaxLength property, this corresponds to a limit of 32 kilobytes (about 32,766 characters). To allow more characters, set the MaxLength property to the desired value, but don't exceed 64 kilobytes (about 65,535 characters).


TIP: When a text box is activated (known as receiving the focus) by the user tabbing to it or clicking in it, a common practice is to select (or highlight) its contents. While there's no automatic way to accomplish this, it can be done pretty easily. One method that I recently discovered has quickly become my favorite. Enter this line of code in the text box's GotFocus event procedure:

SendKeys "{Home}+{End}"

The SendKeys statement sends a string of characters to the active form at run time just as if the user typed them at the keyboard. In this case, we're acting as if the user pressed the Home key, then a shifted End key (the plus sign before {End} represents Shift). This causes the text to be highlighted, so the user can begin entering new text without having to delete what is already there.


Actions

Another control important to practically every application that you will develop is the CommandButton control. Typically, this control is used to let the user initiate actions by clicking the button. Setting up a CommandButton control is quite simple. You draw the button on the form and then set the Caption property of the button to the text that you want displayed on the button's face. To activate the button, just place code in the button's Click event procedure. As any other event procedure, this code can consist of any number of valid Visual Basic programming statements.

While users most often use command buttons by clicking them, some users prefer accessing commands through the keyboard versus using the mouse. This is often the case for data-entry intensive programs. To accommodate these users, you want your program to trigger command button events when certain keys are pressed. You accomplish this by assigning an access key to the command button. When an access key is defined, the user holds down the Alt key and presses the access key to trigger the Click event of the CommandButton control.

You assign an access key when you set the CommandButton control's Caption property. Simply place an ampersand (&) in front of the letter of the key you want to use. For example, if you want the user to be able to press Alt+P to run a print command button, you set the Caption property to &Print. The ampersand does not show up on the button, but the letter for the access key is underlined. The caption Print then appears on the command button.


NOTE: If, for some reason, you need to display an ampersand in a CommandButton caption, simply use two of them in a row in the Caption property--for example, Save && Exit.

In addition to captions, your command buttons can have pictures. Simply set the Style property to Graphical, and use the Picture property to select a picture file. Figure 4.16 shows several options for creating command buttons.

FIG. 4.16
Command buttons can communicate their functions to the user in many ways.

One command button on a form can be designated as the default button. This means the user can simply press Enter while the focus is on any control (except another command button or a text box whose MultiLine property is True) to trigger the default button. This activates the default button's Click event, just as if the user had clicked it with the mouse. To set up a button as the default button, set its Default property to True. Only one button on a form can be the default button.

You can also designate one button as the cancel button, which is similar to the default button but works with the Esc key. To make a command button into a cancel button, set its Cancel property to True. As with default buttons, only one button on a form can be a cancel button. As you set the value of the Default or Cancel property of one button to True, the same property of all other buttons on the form is set to False.

Working with Multiple Controls in the Design Environment

So far, you have seen how to add controls to your forms and how to set the properties of a single control at a time. But sometimes you need to be able to work with multiple controls at the same time. For example, if you have a bunch of label controls on a form and decide to change their font, you don't want to have to select and change each label control individually. That would be a real hassle. Fortunately, you don't have to handle controls one at a time; you can work with them in groups.

The first step in working with multiple controls is to select the controls you need to move or modify. You can select a group of controls by clicking the mouse on your form and dragging it. As you drag the mouse, you see a dashed-line box appear on the form as shown in Figure 4.17. Use this box to enclose the controls you want to select.

FIG. 4.17
You can easily select multiple controls with the mouse.

When you release the mouse button, any controls that are inside the box or touching it are selected. The selected controls are indicated by small boxes at each corner and in the center of each side of the control (see Figure 4.18).

FIG. 4.18
Selection points (boxes) indicate that a control is selected.


NOTE: You can also select multiple controls by holding down the Ctrl key while you click them individually. If you need to select a group of controls that are contained within a frame or picture box, you must Ctrl+click them because the dashed-line box technique won't work.

You can add controls to a group or remove them by clicking the control while holding down the Shift or Ctrl key. You can even do this after making an initial selection with a mouse drag, so you can refine your selection to exactly the group of controls you want to work with.

After the group of controls has been selected, you can move the group as a whole by clicking one of the controls in the group and dragging the group to a new location. The controls retain their relative positions within the group as you move them. You can also use editing operations such as Delete, Cut, Copy, and Paste on the group as a whole.

Using the Properties Window

In addition to the ability to move, cut, copy, paste, and delete a group of controls, you can also work with their properties as a group. For example, if you want to change the font of a group of Label controls, simply select the group of controls and access the Font property in the Properties window. When you change the property, all the selected controls are affected. This is a great tool for making changes to many controls at once. I use this technique frequently to change the alignment of all the Label controls on my form.

While it is obvious that this works for a group of controls of the same type (such as a group of labels or a group of text boxes), you might be wondering what happens when your group includes controls of several different types. In this case, Visual Basic displays the properties that are common to all the controls in the group. These properties typically include Top, Left, Height, Width, Font, ForeColor, Visible, and Enabled. You can only edit the properties that are common to all the controls. However, this is very useful if you want to align the left or top edges of a group of controls. To do this, simply select the group and set the Left property of the group (or the Top property). Figure 4.19 shows a selected group of different controls and the Properties window containing their common properties.

FIG. 4.19
Common properties of different controls can be modified as a group.

Using the Form Editor Toolbar

Editing common properties is ot the only way to work with a group of controls. Visual Basic 5 adds a great tool to the development environment. This tool is the Form Editor toolbar (see Figure 4.20), which is accessible by selecting View, Toolbars, Form Editor. Table 4.7 shows and explains each of the toolbar buttons.

FIG. 4.20
The Form Editor toolbar makes it easy to align and size multiple controls.

Table 4.7 The Form Editor Toolbar Buttons

Button

Name Function

Bring to Front Move selected control in front of other controls on the same part of the form.

Send to Back Move selected control behind other controls on the same part of the form.

Align Lines up a group of controls

Center Centers a group of controls

Make Width Same Size Resizes a group of controls to match

Lock Controls Toggle Prevents movement or resizing of controls with the mouse (however, the controls can still be modified with the Properties window)

The Form Editor toolbar allows you to manipulate the position and size of a group of controls. The Align button allows you to align the left, right, top, or bottom edges of a group of controls. While you can align the left and top edges of a group by setting the Left or Top properties directly, there is no direct way to align the right or bottom edges. The Align button also enables you to line up the vertical or horizontal centers of the controls. This cannot be done directly with the properties. To choose which type of alignment to use, click the arrow button to the right of the Align button. This displays a menu that allows you to pick the alignment. You can also choose to align all the selected controls to the grid. This causes the upper-left corner of each control to be moved so that it is touching the grid point nearest its current location.

Another task that was tedious in previous versions of Visual Basic was centering controls on the form. This has also been made easy using the Form Editor toolbar. Next to the Align button is the Center button. This button allows you to center the group of controls horizontally or vertically within the form. The entire group is centered as if it were a single control; the relative position of each control in the group remains the same. As with the alignment options, you select the type of centering you want from a pop-up menu that appears when you click the arrow button next to the Center button.

The last button on the Form Editor is the Make Same Size button. This button allows you to make the height or width of all the controls in the group the same. While you can do this by setting the appropriate properties, the Form Editor makes it much more convenient.

Figure 4.21 shows a group of controls that has been made the same size as well as centered horizontally within the form.

FIG. 4.21
With the Form Editor toolbar, centering and resizing controls is a snap!


TIP: If you press the wrong button on the Form Editor toolbar, you can undo the changes by clicking the toolbar's Undo button, or by pressing Ctrl+Z.

Using the Format Menu

Just when you thought you had seen every possible way to manipulate multiple controls, you find out that there is one more option available to you--Visual Basic's Format menu (see Figure 4.22). The Format menu contains all of the same functions as the Form Editor toolbar, but also has three other options for working with multiple controls--Horizontal Spacing, Vertical Spacing, and Size to Grid.

FIG. 4.22
The Format menu offers a number of tools for fine-tuning the appearance of controls on your forms.

The Horizontal Spacing option allows you to make the spacing between controls equal. This gives you a clean look for groups of controls such as command buttons. If you think the controls are too close together, you can choose to increase the spacing. The spacing is increased by one grid point. You can also choose to decrease the spacing between controls, or remove the spacing altogether. Choosing Vertical Spacing allows you to perform the same tasks in the vertical direction. Figure 4.23 shows a "before" and "after" look at a group of command buttons. The "after" portion shows the effect of setting the horizontal spacing equal.

FIG. 4.23
Equal horizontal spacing makes this group of buttons look orderly.

The final item on the Format menu is the Size to Grid item. Selecting this option sets the Height and Width properties of each selected control so that it exactly matches the grid spacing.

Working with the Controls Collection

By now, you're probably thinking, "All this is great when I am in the design environment, but what about while my program is running?" Well, as you know, you can change the properties of any single control by specifying the control name, the property name, and the new property value. But does this mean that you have to set each control individually? No way!

Each form contains a collection called the Controls collection. This collection identifies each control that is on the form. Using this collection and a special form of the For loop, you can change a specific property of every control on your form.

Changing All Controls

As an example, you might want to give your users a way to select the font they want to use for the controls on the form. Trying to set each form in code would be a real pain. But, with the For Each loop, you can set the font of every control on the form with just three lines of code (see Listing 4.4).

Listing 4.4 COLLECT.FRM--Collections Enable You to Set Properties for Multiple Controls in Code

For Each Control In Form1.Controls
    Control.Font = "Times New Roman"
Next Control

You can do the same thing with any other properties that are supported by all the controls on the form.

Changing Selected Controls

But what if you want to set a property that is not supported by all the form's controls? For example, if you want to change the text color of your controls, the command button doesn't have a ForeColor property, although other types of controls do. For this problem, you use another code statement, the TypeOf statement. This statement allows you to determine the type of any object. This way, you can set up a routine that changes the ForeColor property of all controls that are not command buttons. This is shown in Listing 4.5.

Listing 4.5 COLLECT.FRM--Using the TypeOf Statement to Omit Specific Controls from Processing

For Each Control In Form1.Controls
    If Not TypeOf Control Is CommandButton Then
        Control.ForeColor = &HFF
    End If
Next Control

From Here...

This chapter has introduced you to the world of forms and controls. You have seen how to control the appearance of forms and controls through their properties and how the methods of forms can be used to perform tasks. You have also seen how to work with multiple controls in both the design environment and in your programs.

The following chapters provide you with even more information about working with forms and controls:


Previous chapterNext chapterContents


Macmillan Computer Publishing USA

© Copyright, Macmillan Computer Publishing. All rights reserved.