Sams Teach Yourself Visual Basic 6 in 24 Hours

Sams Teach Yourself Visual Basic 6 in 24 Hours

By Greg Perry

Option Buttons

Figure 11.1 shows an application with four option buttons. An option button gives your user a choice. By clicking the option button or by sending the focus to the option button and pressing the Spacebar to choose the option, the user selects or deselects an option button. When selected, the option button has a black center inside its circle.

11fig01.gif

Figure 11.1 A form with four option buttons.

Option buttons act in a mutually exclusive fashion. Only one option button can be selected at any one time. Therefore, in Figure 11.1, the user could not select two or more of the options. If the user were to click Texas, the California option would no longer be selected. You don't have to do anything special to ensure that only one option button is selected at any one time; Visual Basic takes care of removing the former option's selection when the user selects a subsequent option button.

The option button supports several of the properties you're already familiar with, such as the Appearance and Alignment properties. The Alignment property determines whether the option button text resides to the left or right of the option button. Figure 11.2 shows the option buttons with their Alignment property set to 2-Right Justify. The alignment you set depends on where the option buttons are to fall in relation to other controls.

11fig02.gif

Figure 11.2 These option buttons have a right-justified Alignment property.

The Value property is perhaps the most important option button property because the Value property changes at runtime and determines whether the option button is currently selected. By the way, the user can select only one option button at a time, but the application may start up without any option buttons being set if you don't set any in the Properties window or in code.

Share ThisShare This

Informit Network