Example with RadioButton:-



Add a new Form i.e.,FormRadio to the Windows Application WABasics
Create one label,one textboxe and four RadioButtons & set the following properties to them


label1:

     Text      :         Enter Any Data
     Name     :         lblSample

textBox1:

     Name     :         lblSample



radioButton1:

     Text      :         Red
     Name     :         optRed

radioButton2:

     Text      :         Green
     Name     :         optGreen

radioButton3:

     Text      :         Blue
     Name     :         optBlue

radioButton4:

     Text      :         Yellow
     Name     :         optYellow



Design :-



 Generate theEventHandler for optRed,optGreen,optBlue,optYellow checkedChanged Events
& write the following code in Source[FormRadio.cs] 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WABasics
{
    public partial class FormRadio : Form
    {
        public FormRadio()
        {
            InitializeComponent();
        }

        private void optRed_CheckedChanged(object sender, EventArgs e)
        {
            txtSample.BackColor = Color.Red;
        }

        private void Green_CheckedChanged(object sender, EventArgs e)
        {
            txtSample.BackColor = Color.Green;
        }

        private void optBlue_CheckedChanged(object sender, EventArgs e)
        {
            txtSample.BackColor = Color.Blue;
        }

        private void optYellow_CheckedChanged(object sender, EventArgs e)
        {
            txtSample.BackColor = Color.Yellow;
        }
       
    }
}



Result :-


No comments:

Post a Comment