articles

Home / DeveloperSection / Articles / Radio Buttons in CSharp .NET

Radio Buttons in CSharp .NET

Anonymous User4844 18-Jul-2010
 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.

Radio Buttons in CSharp .NETRadio Buttons in CSharp .NET

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;
        }

Radio Buttons in CSharp .NET
 
   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
 

Updated 07-Sep-2019
I am a content writter !

Leave Comment

Comments

Liked By