VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

VB .NET - Learn Visual Basic .NET

Systems Analysis - System analysis and Design tutorial for Software Engineering

You are here: Visual Basic > Advanced VB6 tutorial > Chapter 3

Setting Properties for CommandButtons, TextBoxes, and Labels

You can set most of the properties of a control object at either design time or at runtime.

To set a control's property at design time:

3.4 Manipulating a Control's Property at Design Time

  1. Use the F4 key or choose View, Properties from the VB menu to bring up the Properties window, as shown in Figure 3.11.

    Setting properties in the Properties window.
    FIGURE 3.11 - Setting properties in the Properties window.

  2. Find the property in question on the list. You may navigate the properties list by pressing Shift + the first letter of the property name.

  3. Set the property to the appropriate value.

Depending on the nature of the information that the property represents, you will find different ways to set the property:

Properties that can take a wide range of numeric values or a string of text are usually changed by simply typing in the value you want to assign.

Properties that represent Boolean values (such as the CommandButton's Cancel and Default properties) can be toggled by double-clicking them.

Properties that can hold a small range of named, enumerated values (such as the MousePointer property) usually exhibit a drop-down list of the possible values.

Properties (such as Font or BackColor) that contain subcomponents or more visually complex information may popup their own property dialog box or Property Page when you double-click them.

To set a control property at runtime, use the familiar syntax to assign a value to the property. For example if you want to assign the string "Activate" to the Caption property of the CommandButton named cmdExecute at runtime, you would put the line

cmdExecute.Caption = "Activate"

Other properties can take the name of the appropriate VB constant. In the following example, the vbHourGlass constant for the MousePointer can be found in the drop-down list of values at design time. The vbRed constant could be found in the ObjectBrowser's list of the VBRun library's Color constants.

txtName.MousePointer = vbHourGlass
lblName.BackColor = vbRed

Finally, for properties which are complex objects, you may need to use double-dotted syntax to refer to the property of a property of an object, as in the following examples with sub-properties of the Font property of a TextBox:

txtInvitation.Font.Bold = True
txtInvitation.Font.Name = "Arial"


<< Previous | Contents | Next >>

Home | About Us | Privacy Policy | Contact Us

Copyright © | All Rights Reserved