RadioButton Control in C#.Net

RadioButton Control in C#.Net

The RadioButton controls 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 replaced by the second.

How to use RadioButton Control

Drag and drop three RadioButton from the toolbox on the window Form.

RadioButton Control in C#.Net

Code:

Write code in CheckedChanged event of RadioButton.

RadioButton Control in C#.Net

Double click on CheckedChanged event.

private void radioButton1_CheckedChanged(object sender,  EventArgs e)
{
   //RadioButton1 value will show in Label1 if RadioButton1 is selected
   label1.Text ="Selcted Language is  "+ radioButton1.Text;
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
   //RadioButton2 value will show in Label1 if RadioButton2 is selected
    label1.Text = "Selcted Language is  " + radioButton2.Text;
}
 
 private void radioButton3_CheckedChanged(object sender, EventArgs e)
 {
    //RadioButton3 value will show in Label1 if RadioButton3 is selected
    label1.Text = "Selcted Language is  " + radioButton3.Text;
 }

 Run the project

RadioButton Control in C#.Net

 

When you select any given option then CheckedChanged event will fire and selected value will show in the Label.

RadioButton Control in C#.Net

RadioButton Properties:

Appearance: Default value is Normal. Set the value to Button if you want the RadioButton to be displayed as a Button.

Example:

//set checkbox appearance as button
private void frmRadioButton_Load(object sender, EventArgs e)
{
      radioButton1.Appearance = Appearance.Button;
      radioButton2.Appearance = Appearance.Button;
      radioButton3.Appearance = Appearance.Button;
}


RadioButton Control in C#.Net

Now RadioButton appearance is as button.

CheckAlign: CheckAlign property is used to align the check mark in a RadioButton.

BackColor:  RadioButton BackColor can be changed through BackColor Properties of RadioButton.

Example:

//Change RadioButton BackColor
private void frmRadioButton_Load(object sender, EventArgs e)
{  
      radioButton1.BackColor = Color.CadetBlue;
      radioButton2.BackColor = Color.CadetBlue;
      radioButton3.BackColor = Color.CadetBlue;
}

RadioButton Control in C#.Net

  Modified On Mar-04-2020 03:48:33 AM

Leave Comment