Using Windows Controls and Properties


STEP1:-Design form as follows

0.gif

STEP2:-Apply TAG  values as follows to each control as follows

1.gif

STEP3:-Create a event  private void checkBox_CheckedChanged

3.gif

And then bind each checkbox to the event we created.

Do the same thing for the Radio buttons creating radioButton_CheckedChanged event.

Code is as follows:

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 WindowsProject
{
    public partial class Form6 : Form
    {
        int counter = 0;
        public Form6()
        {
            InitializeComponent();
        }
        private void checkBox_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox cb = sender as CheckBox;
            int amt = int.Parse(txtAmount.Text);
            if (cb.Checked)
            {
                counter += 1;
                amt += Convert.ToInt32(cb.Tag);
            }
            else
            {
                counter -= 1;
                amt -= Convert.ToInt32(cb.Tag); ;
            }
            txtAmount.Text = amt.ToString();
            if (counter == 0)
                radioButton1.Checked = true;
        }
        private void radioButton_CheckedChanged(object sender, EventArgs e)
        {
            int amt = int.Parse(txtAmount.Text);
            if (amt > 0)
            {
                RadioButton rb = sender as RadioButton;
                if (rb.Checked)
                    amt += Convert.ToInt32(rb.Tag);
                else
                    amt -= Convert.ToInt32(rb.Tag);
                txtAmount.Text = amt.ToString();
            }
            else
                radioButton1.Checked = true;
        }
    }
}

erver'>
Up Next
    Ebook Download
    View all
    Learn
    View all