In the Form with the CheckBoxes:
0. define as Public a Dictionary<string,CheckState> named 'ChkBoxToChkState:
public Dictionary<string,> ChkBoxToChkState;
0.a. initialize that Dictionary in the Form Load Event
private void Form2_Load(object sender, EventArgs e)
{
ChkBoxToChkState = new Dictionary<string, CheckState>
{
{checkBox1.Name, checkBox1.CheckState},
{checkBox2.Name, checkBox2.CheckState},
{checkBox3.Name, checkBox3.CheckState},
};
}
1. in the Form Design view: select all the CheckBoxes
1.a. use F4 to open the Property Browser, click the Events tab
1.b. click on the 'CheckStateChanged entry to automatically generate an Event Handler in your code that will look like this:
private CheckBox currentCheckBox;
private void checkBox1_CheckStateChanged(object sender, EventArgs e)
{
currentCheckBox = sender as CheckBox;
ChkBoxToChkState[currentCheckBox.Name] = currentCheckBox.CheckState;
}
In the Form that will need to evaluate the state of the CheckBoxes:
0. assume you have created an instance of the Form with the CheckBoxes named 'CBForm, and that it has been shown ... i.e., you can be sure the Dictionary on that Form is properly instantiated.
1. write the method that evaluates the CheckBoxes:
private void EvaluateForm2CheckBoxState()
{
var cBoxState = CBForm.ChkBoxToChkState;
if (cBoxState == null) return;
if(
cBoxState["checkBox1"] == CheckState.Checked
&& cBoxState["checkBox2"] == CheckState.Checked
)
{
Console.WriteLine("rule 1");
}
else if(false)
{
Console.WriteLine("rule ?");
}
else
{
Console.WriteLine("final rule ?");
}
}
Note the choice made here: to use Type 'string as the Key in the Dictionary: that means the user (you) cannot change the CheckBoxes CheckState from outside the CheckBox Form.
If you need the ability to change the CheckState, from the Main Form, then you could use the CheckBoxes as the Key in the Dictionary.
Note also the assumption here that accessing the values of the CheckBoxes is done "on demand," rather than being triggered by some user-action (like changing the CheckState Value in a CheckBox in the Form with the CheckBoxes).