C#显示已选中次数Checkbox / RadioBox的次数

时间:2013-11-25 03:49:18

标签: c# checkbox

我正在制作一个应用程序,根据所选的复选框和单选按钮计算总数。但后来我想看看在另一个表单或消息框中选择了多少作为摘要功能。

实施例

User 1 selects: RadioButton 1 and Checkbox 1 and 2,

User 2 selects: radiobox 2 and Checkbox 2

User 3 selects RadioBox 1 and Checkbox 2

摘要结果

RB1= 2

RB2= 1

CB1= 1 

CB2= 2

有谁知道代码是什么来计算选择CB和RB的次数?

我的代码到目前为止

   {
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
    const int Lunch = 25;
    const int Early = 40;
    const int Late = 40;
    const int Table = 10;
    const int Waiter = 20;

    int Meal;
    int Mealprice;
    int Extras;
    const int TotalLunch = 1;
    int TotalEarly = 1;
    int TotalLate = 1;
    int TotalWaiters = 1;
    int TotalTables = 1;

    private void calculateButton_Click(object sender, EventArgs e)
    {
        int Quantity; 
        int Finalprice;

        if (lunchRadioButton.Checked == true)
        {
           Meal = Lunch;
           TotalLunch.ToString();
        }
        else if (tableCheckBox.Checked && waiterCheckBox.Checked)
        {
            Extras = Waiter + Table;
            TotalWaiters.ToString();
            TotalTables.ToString();
        }
        else if (waiterCheckBox.Checked)
        {
            Extras = Waiter;
            TotalWaiters.ToString();
        }
        else if (tableCheckBox.Checked)
        {
            Extras = Table;
            TotalTables.ToString();
        }

        //Early Evening Meal
        if (earlyEveningRadioButton.Checked == true)
        {
            Meal = Early;
            TotalEarly.ToString();
        }

        else if (tableCheckBox.Checked && waiterCheckBox.Checked)
        {
           Extras = Table + Waiter;
           TotalWaiters.ToString();
           TotalTables.ToString();
        }
        else if (waiterCheckBox.Checked)
        {
            Extras = Waiter;
            TotalWaiters.ToString();
        }
        else if (tableCheckBox.Checked)
        {
            Extras = Table;
            TotalTables.ToString();
        }

        //Late evening options
        if (lateEveningRadioButton.Checked == true)
        {
            Meal = Late;
            TotalLate.ToString();
        }

        //Late Evening, Corner table and Dedicated waiter selected.
        else if (tableCheckBox.Checked && waiterCheckBox.Checked)
        {
            Extras = Table + Waiter;
            TotalWaiters.ToString();
            TotalTables.ToString();
        }

        //Late Evening and Dedicated waiter selected.
        else if (waiterCheckBox.Checked)
        {
           Extras = Waiter;
           TotalWaiters.ToString();
        }

        //Late Evening and Corner Table
        else if (tableCheckBox.Checked)
        {
            Extras = Table;
            TotalTables.ToString();
        }

        try
        {
            Quantity = int.Parse(guestTextBox.Text);
            Mealprice = (Meal * Quantity);
            Finalprice = (Mealprice + Extras);
            finalAmountLabel.Text = Finalprice.ToString("C");

        }
        catch
        {
            MessageBox.Show("Please enter a quantity in numerical form","Quantity Error!");
        }


    }

1 个答案:

答案 0 :(得分:0)

没有任何原生内容会跟踪点击任何内容的次数。您需要连接OnClick事件并在代码中跟踪每个事件。