Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
(Publisher: The Coriolis Group)
Author(s): Peter G. Aitken
ISBN: 1576102815
Publication Date: 08/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Setting The Remaining Properties

The last part of creating the project’s visual interface is setting the properties of the controls. Start by selecting the Frame, then scroll the Properties list to bring its Caption property into view. Double-click on the Caption property name, type “Text Colors”, and press Enter. (This is the very same method you used to set the Text property for the Text Box, remember?) Visual Basic maintains as much consistency as possible in the techniques for dealing with properties, which makes the learning process move as quickly as possible.


Figure 3.6  Placement of the Frame, Option Buttons, and Command Buttons.

Next, select the top Option Button. Set its Name property to optBlack and its Caption property to Blac&k. That’s not a typo—an ampersand goes before the k. What’s that for? And what is the Name property?

If you place an ampersand in a control’s Caption property, the ampersand does not display on the form, but it causes the following letter—in this case, the k—to be underlined. This defines an access key for the control. When the program is running, the user can select the control by pressing Alt+letter, and the effect will be the same as clicking on the control. Because some people prefer to use the keyboard rather than the mouse, it’s wise to provide keyboard alternatives for as many program tasks as possible. Access keys are one way to do this.

A control’s Name property is used to refer to the control in Basic code. While all controls are given a default name when you create them, assigning names that reflect both the type of control and its specific function is a good idea. Thus, the name optBlack identifies an Option Button that sets the Black option. Note that we did not change the default names of the Text Box or the Frame controls. We will not need to refer to the Frame in code, so its Name property is irrelevant. With only one Text Box in the project and no chance of confusion, its default name of Text1 will be okay.

We need to change one more property for this Option Button control. Scroll the Properties list to display the Value property, click on it, and then click on the down arrow in the right column. You’ll see two possible values for this property—True and False—corresponding to on and off states for the Option Button. The default value is False, but we want to set this one to True.


TIP:  Rapid True/False Changes

Numerous properties take True/False values. To toggle the property quickly from one value to the other, double-click on it in the properties list.


Change the properties for the remaining two Option Buttons as follows:

Second Option Button

Caption: &Red
Name: optRed

Third Option Button

Caption: &Blue
Name: optBlue

We’ll leave the Value property at False for these two buttons. We really have no choice here, because we’ve already set the Value property of the first Option Button in this group (optBlack) to True, and only one button in a group can be on at a time. If you did set the Value property of one of the other buttons to True, the Value property of the optBlack button would automatically switch to False.

We also need to change the ForeColor property of the second and third Option Buttons. This property sets the color of the control’s caption text (the first Option Button will be left at its default ForeColor property of black). Scroll down to the ForeColor property. You’ll see a property value that is a weird-looking combination of letters and numbers, something like this:

&H80000012&

What kind of color is this? Actually, it’s a number that represents a color—in this case, black. The leading &H identifies it as a hexadecimal number, and the trailing & indicates that it’s a type Long number. If you don’t know what I’m talking about here, don’t fret; you’ll learn about these things in Chapter 4. But why does Visual Basic use a number to represent a color? Couldn’t it have used something easier to work with, like a color name or a sample of the color?

I agree that the numbers are useless—and fortunately, you don’t need to work with them directly. If you select the ForeColor property and click on the down arrow in the property value column, Visual Basic displays a small dialog box. Click the Palette tab if necessary to display a palette of the available colors, as shown in Figure 3.7. Select a shade of Blue for the optBlue button and a shade of red for the optRed button.

The final properties you need to set are for the three Command Buttons. I’m sure by now you’re well acquainted with the process of setting properties, so I won’t repeat the steps. Here are the properties to set:


Figure 3.7  Selecting a color for the ForeColor property.

Upper Command Button

Caption: &Bigger
Name: cmdBigger

Middle Command Button

Caption: &Smaller
Name: cmdSmaller

Lower Command Button

Caption: &Quit
Name: cmdQuit


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |&nbs