Wednesday, 22 May 2013

C# how to use Radio Button in Form application










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

namespace march_19pt2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            rdoMale.Checked = true;
            rdoFemale.Checked = true;


        }
        private void btnExit_Click(object sender, EventArgs e)
        {
              string output;
        //Frist if else determining gender
         if(rdoMale.Checked==true)

         output = "male checked";
          else
                output = "Female checked";
                //second if else determining age
                if(rdoAbover20.Checked == true)
                    output+= " and age is greaater than 20";
                    else
                    output += "and age is below 20";
                MessageBox.Show(output);
        }
        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            btnExit_Click(this , e);
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            btnExit_Click(this, e);
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            btnExit_Click(this, e);
        }

        private void radioButton4_CheckedChanged(object sender, EventArgs e)
        {
            btnExit_Click(this, e);
        }

        private void btnExit_Click_1(object sender, EventArgs e)
        {

        }

      
    }
}

No comments:

Post a Comment