Thursday, 4 April 2013

Example showing an application using RadioButton and CheckBox




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 WinForms7
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }
        int count = 0;

        private void checkBox1_CheckedChanged_1(object sender, EventArgs e)
        {
            {
                radioButton1.Checked = true;
                int amt = int.Parse(txtFees.Text);
                CheckBox cb = sender as CheckBox;
                if (cb.Checked)
                {
                    count += 1;
                    amt += Convert.ToInt32(cb.Tag);
                }
                else
                {
                    count -= 1;
                    amt -= Convert.ToInt32(cb.Tag);
                }
                txtFees.Text = amt.ToString();
            }
        }
      
        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            int amt=int.Parse (txtFees .Text);
            RadioButton rb = sender as RadioButton;
            if(rb.Checked )
                amt+=(Convert .ToInt32 (rb.Tag )*count );
            else
            amt-=(Convert .ToInt32 (rb.Tag )*count );
            txtFees.Text = amt.ToString();
        }

        private void btnReset_Click(object sender, EventArgs e)
        {
            foreach (Control ctrl in groupBox1.Controls)
            {
                CheckBox cb = ctrl as CheckBox;
                cb.Checked = false;
            }
            foreach (Control ctrl in this.Controls)
            {
                if (ctrl.GetType().Name == "TextBox")
                {
                    TextBox tb = ctrl as TextBox;
                    tb.Clear();
                }
                txtFees.Text = "0";
                txtName.Focus();
                    
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        }
    }

No comments:

Post a Comment