We use Radio Button, when we want user to select only one options from given list of options. Here below I am using three radio buttons Red, Blue, Green, so when user will select Red radio button then the background color of form will be changed.
Here are the screen shots.
Code
setting radio button checked option to false on form load
private void radio_Load(object sender, EventArgs e)
{
rdoRed.Checked= false;
rdoBlue.Checked= false;
rdoGreen.Checked= false;
}
On radio button click changing the color of form back color and fore color according to selected radio button.
private void rdoRed_Click(object sender, EventArgs e)
{
this.BackColor= Color.Red;
gbColor.ForeColor= Color.Yellow;
btnDefault.ForeColor= Color.Black;
}
private void rdoBlue_Click(object sender, EventArgs e)
{
this.BackColor= Color.Blue;
gbColor.ForeColor= Color.Yellow;
btnDefault.ForeColor= Color.Black;
}
private void rdoGreen_Click(object sender, EventArgs e)
{
this.BackColor= Color.Green;
gbColor.ForeColor= Color.Yellow;
btnDefault.ForeColor= Color.Black;
}
Green option Selected
Changing the form backcolor and forecolor to default color on button click. And unchecking radio button
private void btnDefault_Click(object sender, EventArgs e)
{
this.BackColor =DefaultBackColor;
gbColor.ForeColor= DefaultForeColor;
rdoRed.Checked= false;
rdoBlue.Checked= false;
rdoGreen.Checked= false;
}
Default Button Clicked
Manish Kumar
16-Jun-2017This article is truly nice.