0

I have a mini setup program written using Windows Forms and C# and have a problem.

I have four CheckBox controls and I want to get checked info and use it on another form so it provides which checkbox is checked. The other form shows only checked module list based on which check boxes are checked.

How can I show only checked modules in Form2?

4

2 回答 2

0

You need to pass that information into the second form.

So, on From2 you can add a method that takes a list of bool values or similar and make this method public.

 // put this method in Form2
 public void SetModules(IList<bool> modulesEnabled)
 {
     // here you can test whether a certain module is enabled
     //    by checking modulesEnabled[0], modulesEnabled[1], etc.
 }

From Form1, before showing From2 you would get the state of the checkboxes and construct the modulesEnabled array. Then invoke SetModules on Form2.

 Form2 secondForm = new Form2();

 IList<bool> modulesList = new List<bool>();
 modulesList.Add(checkBox1.Checked);
 modulesList.Add(checkBox2.Checked);
 modulesList.Add(checkBox3.Checked);
 modulesList.Add(checkBox4.Checked);

 secondForm.SetModules(modulesList);      // make sure to call this BEFORE showing Form2

 secondForm.Show();
于 2013-08-06T14:54:13.710 回答
0

在我知道更多之前,我会给你一些想法:

Form2可以在他的构造函数中获取Form1Form1给出如下方法:

  public bool IsCheckboxChecked(int checkIndex)
  {
     if (checkIndex == 1)
     {
        return checkBox1.Checked;
     }
     else if (checkIndex == 2)
     {
        return checkBox2.Checked;
     }
     else if (checkIndex == 3)
     {
        return checkBox3.Checked;
     }
     else if (checkIndex == 4)
     {
        return checkBox4.Checked;
     }
     else
     {
        return false;
     }
  } 
于 2013-08-06T14:56:12.177 回答