Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

174 Part II Programming Fundamentals



  1. Click the Label control in the Toolbox, and then draw a label near the top of the form to
    display a title for the program.

  2. Use the Label control to create a second label object below the first.


You’ll use this label as a title for the list box.


  1. Click the ListBox control in the Toolbox, and then create a list box below the second
    label.

  2. Use the Label control to draw two more labels below the list box to display program
    output.

  3. Use the Button control to create a small button on the bottom of the form.

  4. Open the Properties window, and then set the properties as shown in the following
    table, for the objects that you have just created.


Object Property Setting
Form1 Text “Case Greeting”
Label1 Font
Name
Text

Times New Roman, Bold, 12 point
lblTitle
“International Welcome Program”
Label2 Name
Text

lblTextBoxLabel
“Choose a country”
Label3 Font
Name
Text

Microsoft Sans Serif 10 point
lblCountry
(empty)
Label4 AutoSize
BorderStyle
ForeColor
Name
Text

False
Fixed3D
Red
lblGreeting
(empty)
ListBox1 Name lstCountryBox
Button1 Name
Text

btnQuit
“Quit”

Since there are so many objects, you’ll also assign Name properties to help you easily
identify the control on the form and within your program code. (When the properties in
the Properties window are sorted alphabetically, you’ll find Name listed in parentheses
near the top of the Properties window. When the properties in the Properties window
are sorted by category, you’ll find Name listed in parentheses in the Design category .)
I recommend that you use the Name property whenever you have more than four or
five objects in a program. In this example, I’ve given the objects names that feature
a three-character prefix to identify the object type, such as btn (for button), lbl (for
label), and lst (for list box).
Free download pdf