private void btnConfirm_Click(object sender, EventArgs e) { foreach (Control crl in Controls) { CheckBox cbx = new CheckBox(); if(crl.GetType() == cbx.GetType()) { cbx = (CheckBox)crl; } else { return; } if (cbx.Checked) chosenQualifications.Add(cbx.Text); Close(); } }
static string GetCheckBoxState(CheckBox checkbox) { return checkbox.GetType().ToString() + ":" + (checkbox.Checked == true ? "1" : "0"); }