如何将复选框表单值传递给另一个表单

如何将复选框表单值传递给另一个表单

问题描述:

我的项目包含4个复选框和2个按钮,它们将打开两个带有相同复选框值的新表单,这些表单位于我的第一个表单上(如果选中,它们将在两个表单上显示为选中,如果未选中,它们将显示为正常)如果我们选择3个复选框并单击第二个按钮,则打开一个新表单,标签应显示200.如果我选择另一个文本框,标签应更新为300并增加++,如果我取消选中复选框,则值应为减少!!你的任何帮助都是值得的!谢谢

My project contains 4 check boxes and 2 buttons which will open two new form with same check box values which were on my first form(if selected, they will appear as selected on two forms, if not selected they will appear as normal) in which if we select 3 check boxes and click 2nd button it open a new form and a label should display 200. If i select another text box the label should update to 300 and increment ++ and if i unchecked checkbox, the value should be decrease!! any help from you can be appreciable! thank you

您是否尝试过将参数添加到表单的构造函数中?

这可以通过多种方式完成下面的代码只是一个例子:

Have you tried to add a parameter to the constructor of your forms?
This can be done in many ways and the code below is just one example:
public class Form2 : Form
{
    public Form2(params bool checkBoxValues)
    {
        InitializeComponent();
        
        if (checkBoxValues.Length > 0)
            checkBox1.Checked = checkBoxValues[0];
        if (checkBoxValues.Length > 1)
            checkBox2.Checked = checkBoxValues[1];
        if (checkBoxValues.Length > 2)
            checkBox3.Checked = checkBoxValues[2];
    }
}

Form2 frm = new Form2(checkBox1.Checked, checkBox2.Checked, checkBox3.Checked);
frm.ShowDialog();