- The button control is one of the most recognizable controls in Windows programs. Despite its simple appearance, the button has a slew of properties you can change to suit your program's needs. You can change the order in which the button is highlighted when the user presses the Tab key (TabIndex), completely change the appearance of the button by loading a custom image into it (Image property), or simply change the button's Text with the Text property.
- You can change the Text and other properties either in the Visual Basic form design window, or using Visual Basic code. Using the form design window to change object properties involves navigating to View>Designer and single-clicking a control, such as a button control, on your form. With the button now selected, you can use the Properties window to find the Text property and type the new text you want the button to display. The button will show the new text when you're done typing.
- You can also change a control's properties through code. For the button example you might use a line like Button1.Text = "PushMe!". You would use this statement in a subroutine that gets executed as soon as the program starts. The Form1_Load subroutine would be a good candidate for this.
-
You might wonder why you would bother with typing code to change properties, when you could use the more visually intuitive form designer. Use code instead of the designer for a number of reasons, one of them being efficiency. If you're changing many control properties to the same value, writing code to do so is much speedier than entering by hand each control's property. For example, disabling each control on a form can be done with the following three lines.
For Each ct As Control In Me.Controls
ct.Enabled = False
Next
Also, events may occur during your program's execution that require you to change a certain property to one value, and then to another value when another event occurs. There's obviously no way you could change the property during design time to accommodate this run-time situation. Changing the property through code is thus, the only logical choice. - Some properties are common to all or nearly all Visual Basic controls while others are unique to specific controls. The Visible property, for example, exists for each control; you obviously want to have the choice of changing any object's visibility. On the other hand, the LinkBehavior property is found only in the LinkLabel control. You wouldn't expect an option control button to have such a property, as it has nothing inherently to do with a Hypertext link.










