The RadioButton control is used to provide a set of mutually exclusive options. The user can select one radio button in a group. If you need to place more than one group of radio buttons in the same form, you should place them in different container controls like a GroupBox control.
TheChecked property of the radio button is used to set the state of a radio button. You can display text, image or both on radio button control. You can also change the appearance of the radio button control by using the Appearance property.
The following are some of the commonly used properties of the RadioButton control:
|1||Appearance||Gets or sets a value determining the appearance of the radio button.|
|2||AutoCheck||Gets or sets a value indicating whether the Checked value and the appearance of the control automatically change when the control is clicked.|
|3||CheckAlign||Gets or sets the location of the check box portion of the radio button.|
|4||Checked||Gets or sets a value indicating whether the control is checked.|
|5||Text||Gets or sets the caption for a radio button.|
|6||TabStop||Gets or sets a value indicating whether a user can give focus to the RadioButton control using the TAB key.|
The following are some of the commonly used methods of the RadioButton control:
|S.N||Method Name & Description|
|1||PerformClick Generates a Click event for the control, simulating a click by a user.|
The following are some of the commonly used events of the RadioButton control:
|1||AppearanceChanged||Occurs when the value of the Appearance property of the RadioButton control is changed.|
|2||CheckedChanged||Occurs when the value of the Checked property of the RadioButton control is changed.|
Consult Microsoft documentation for detailed list of properties, methods and events of the RadioButton control.
In the following example, let us create two groups of radio buttons and use their CheckedChanged events for changing the BackColor and ForeColor property of the form.
Let's double click on the radio buttons and put the follow code in the opened window.
Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load ' Set the caption bar text of the form. Me.Text = "fastlearning.in" End Sub Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged Me.BackColor = Color.Red End Sub Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.CheckedChanged Me.BackColor = Color.Green End Sub Private Sub RadioButton3_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton3.CheckedChanged Me.BackColor = Color.Blue End Sub Private Sub RadioButton4_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton4.CheckedChanged Me.ForeColor = Color.Black End Sub Private Sub RadioButton5_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton5.CheckedChanged Me.ForeColor = Color.White End Sub Private Sub RadioButton6_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton6.CheckedChanged Me.ForeColor = Color.Red End Sub End Class