ARadioButton control represents one of an exclusive set of options. For example, suppose that you want to let the user select between the choices Small, Medium, and Large. You could add three RadioButtons to a form with those captions. When the user clicks one button, Visual Basic selects it and deselects the others.
All the RadioButton controls within a particular container are part of the same RadioButton group. If the user clicks a RadioButton, Visual Basic automatically deselects the others in the same group.
If you want to make more than one group on the same form, you must place the controls in separate containers (such as GroupBox or Panel controls). For example, you could put the Small, Medium, and Large buttons in one GroupBox and then put the Red, Green, and Blue buttons in another GroupBox. Then, when the user selects a size button, the other size buttons are deselected, but the color buttons are unaffected. When the user selects a color, the other colors are deselected, but the size buttons are unaffected.
RadioButton groups provide special navigation for the user. If one of the buttons in the group has the focus, then the user can press the arrow keys to move forward and backward through the group. If the user presses the Tab key, focus moves out of the group to the next control in the tab sequence.
The following table describes the RadioButton control’s most useful properties.
Property | Purpose |
---|---|
Appearance | Determines whether the control displays with its default appearance of a selection circle containing a black dot (Appearance = Normal) or a raised button (Appearance = Button). |
AutoCheck | Determines whether the control automatically selects itself when the user clicks it. If this is False, the code must check and uncheck the control and any other controls in the RadioButton group. Usually it’s better to use a CheckBox control instead if you don’t want the button to behave like a normal RadioButton. |
CheckAlign | Determines whether the control’s selection circle is positioned in the bottom center, top center, middle right, and so forth. |
Checked | Determines whether the control is selected. |
Image | Determines the image that the control displays. |
ImageAlign | Determines whether the control’s image is positioned in the bottom center, top center, middle right, and so forth. |
Text | Determines the text that the control displays. |
TextAlign | Determines whether the control’s text is positioned in the bottom center, top center, middle right, and so forth. |
The RadioButton control’s most useful events are Click, which occurs when the user clicks the control, and CheckedChanged, which occurs when the control is checked or unchecked either because the user clicked a RadioButton in the group or because the code changed the button’s state.