RadioButton Control in VB.Net

A radio button, also known as an option button, is a graphical user interface element that offers users the ability to select only one option from a predefined set of choices. When a user clicks on a radio button, it becomes "checked," indicating the user's selection, while all other radio buttons within the same group become "unchecked." This exclusive selection behavior distinguishes radio buttons from check boxes.

Radio buttons and check boxes

Radio buttons and check boxes serve different purposes in user interfaces. Radio buttons are ideal when you want the user to choose a single option from a set of alternatives. In contrast, check boxes are suitable when you want the user to select multiple options that are independently applicable.

vb.net-radiobutton.jpg

Similar to check boxes, radio buttons possess a Checked property that reflects whether the radio button is currently selected or not. This property allows you to programmatically determine the state of a radio button and perform corresponding actions based on the user's selection.

Full Source VB.NET
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load RadioButton1.Checked = True End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If RadioButton1.Checked = True Then MsgBox("You are selected Red !! ") Exit Sub ElseIf RadioButton2.Checked = True Then MsgBox("You are selected Blue !! ") Exit Sub Else MsgBox("You are selected Green !! ") Exit Sub End If End Sub End Class

Conclusion

You can enhance the user experience by providing clear and intuitive options for selecting a single choice among several alternatives. Understanding the distinction between radio buttons and check boxes enables you to employ the appropriate control for different scenarios, ensuring a streamlined and user-friendly interface.