RadioButton are used when we need to make multiple sets of choices available, but we want the user to select only one of them. If they click on a second selection after making a first, the first selection is removed and replaced by the second.
Drag and drop RadioButton from toolbox on the window Form.
Code:
Public Class Form15
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
'RadioButton1 value will show in Label3 if RadioButton1 is selected
Label3.Text = "Selected Language is " + RadioButton1.Text
End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
'RadioButton2 value will show in Label3 if RadioButton2 is selected
Label3.Text = "Selected Language is " + RadioButton2.Text
End Sub
Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
'RadioButton3 value will show in Label3 if RadioButton3 is selected
Label3.Text = "Selected Language is " + RadioButton3.Text
End Sub
End Class
When you select any given option then CheckedChanged event will fire and selected value will show in the Label.
RadioButton Properties
BackColor: RadioButton BackColor can be changed through BackColor Properties of RadioButton.
Private Sub Form15_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' change BackColor of RadioButton
RadioButton1.BackColor = Color.Salmon
RadioButton2.BackColor = Color.Salmon
RadioButton3.BackColor = Color.Salmon
End Sub
CheckAlign: CheckAlign property is used to align the check mark in a RadioButton.
Appearance: Default value is Normal. Set the value to Button if you want the RadioButton to be displayed as a Button.
'set checkbox appearance as button
Private Sub Form15_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
RadioButton1.Appearance = Appearance.Button
RadioButton2.Appearance = Appearance.Button
RadioButton3.Appearance = Appearance.Button
End Sub
Now RadioButton will show as button.
Leave Comment