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


Adding The Label Controls

Working with the blank form and the toolbox, we’ll place the four Label controls on the form. First, if you did not follow the procedures earlier in this chapter, you need to start Visual Basic and select Standard EXE from the New Project dialog box. If the toolbox is not displayed, select View|Toolbox. Then follow these steps to place the first label:

1.  Point the mouse cursor at the Label button in the toolbox and click. The Label button is in the second row and has a large A on it.
2.  Move the mouse pointer to the form, where it will display as a cross. Point at the location where you want the top left corner of the first label to be located. You can always change the control’s position and size later, so don’t worry about being precise.
3.  Click and hold the left mouse button, and move the pointer to the opposite corner of the Label. As you do this, you’ll see a rectangular outline follow the pointer, indicating the label size. This technique is called dragging. You’ll also see a small window open that displays the height and width of the control as you drag. This is useful when you need to make your control a specific size, but for now, we’ll just work visually.
4.  When the outline size appears as you want it, release the mouse button. Visual Basic will place a Label control with the caption Label1 on the form, as shown in Figure 2.3. Don’t worry if your form size or label location is not exactly like the figure.

Now that the Label control is on the form, let me call your attention to three things:

  The new control has eight small boxes displayed around its perimeter. These are called handles and are used to change the size and shape of the control. Point at one of the handles, and you’ll see the mouse pointer change to a double-headed arrow. Click and hold the mouse button, drag the control outline to the desired size and shape, then release the mouse button. You can also move the control without changing its size by pointing inside the control (not at a handle) and dragging to the new location.


Figure 2.3  The form after adding the first Label control.

  If you try to change the size or position of the Label control, you are constrained by the grid of dots. In other words, you cannot set a size or position between the dots. This snap-to-grid feature is helpful in designing neat forms with nicely aligned controls. It can be turned off if you need finer control in placing objects, but I suggest that you leave it on for the present.
  The Properties window displays the new control’s properties. This is shown in Figure 2.4. Make the Properties window active by clicking on its title bar (the bar at the top of the window that says “Properties - Label1”). You can now scroll through the list of properties using the scroll bar at the right of the window. The left column lists the property name, and the right column lists the current value (setting) of each property. As you can see, we have no shortage of properties here. Don’t be intimidated—you’ll learn about these properties while working through the book.


Figure 2.4  The Properties window displays the properties of the currently selected object.

Changing The Label Control’s Properties

When you add a control to a form, Visual Basic assigns the default set of properties to the control. For now, we are interested in the Caption property, which specifies the text that the label displays on the form. We’ll need to change the current value of this property, Label1, so the label will identify one of the Text Box controls that we will be placing on the form. Use the following steps:

1.  Be sure that the Label control you just placed on the form has handles displayed around it. If not, click on the control to activate the handles.
2.  Double-click on the Caption property name in the left column of the Properties window. You may need to scroll the properties list to bring the Caption property into view. The current caption Label1 in the right column of the Properties window will be highlighted—that is, it will display as white letters on a dark background.
3.  Type the new caption “Annual interest rate:”. The old caption will be replaced by what you type. If you make an error, press the Backspace key to erase it.
4.  When you finish, press Enter.

You may find that the new caption is too long for the Label control and that the end of the text is cut off. No problem. Simply point at the handle on the right border of the control and click, hold, and drag to stretch it until it’s big enough.

Okay, the first Label control is finished. We need three more for this project, which you can create by using the same techniques. Go ahead and add the three additional Label controls to the form, then change their Caption properties to read:

Loan period (months):
Loan amount:
Monthly payment:

Your form will now look similar to that of Figure 2.5. Note that you can change the size of the form itself at any time. First, select the form by clicking on it. A selected form displays eight handles, three of them dark (as shown in the figure). Point at one of these dark handles and drag to change the form’s size.

Adding The Text Box Controls

With the Label controls in place, the next step is to add the four Text Box controls that we outlined in our planning stage. The procedure is similar to what you just learned, but I’ll walk you through it anyway.

1.  Click on the Text Box icon in the toolbox. This icon has a white box with ab in it and is usually located just to the right of the Label icon.


Figure 2.5  The project’s form after adding the four Label controls.

2.  Place the mouse pointer on the form where you want the Text Box located and press and hold the mouse button.
3.  Drag to place the Text Box.
4.  Release the mouse button.

Repeat these steps to add all four Text Boxes, placing each one to the right of each Label. You’ll see that each Text Box is assigned a default caption of Text1, Text2, and so on. We’ll change those next.

Changing Text Box Properties

As with the Label controls, we’ll need to modify some properties of the Text Box controls that we just placed on the Mortgage Calculator form. This time, however, two properties need changing for each of the four Text Boxes. One is the Text property, which controls the text that is displayed in the Text Box. We want to specify a blank Text property, so the Text Box control is empty when the program starts. The other is the Name property, which specifies the identifying name associated with the control. We want to assign a meaningful name. Here are the steps to follow for the first Text Box:

1.  Click on the Text Box that is next to the Annual interest rate: label so that its handles are displayed.
2.  Double-click on the Text property in the Properties window (you may have to scroll through the Properties window to bring the desired property into view). The current setting, Text1, will be highlighted.
3.  Press the Del key to erase the text.
4.  Press Enter.
5.  Double click on the Name property in the Properties window (again, scrolling if necessary).
6.  Type “txtInterestRate”.
7.  Press Enter.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |