mardi 23 mars 2021

Loop through all unchecked Checkboxes (foreach or for-loop, Windows Forms)

I would like to compress the executable code segment (see below). How to do this with a foreach or for-loop?

private void UncheckCheckBox() 
{
   CheckBox[] Three = new [] 
   {
     checkBox1,
     checkBox2,
     checkBox3
   };

   checkBox1.Tag = "str1";
   checkBox2.Tag = "str2";
   checkBox3.Tag = "str3";

   if (!checkBox1.Checked) 
   {
     listBox4.Items.Remove(checkBox1.Tag);
   }
   if (!checkBox2.Checked) 
   {
     listBox4.Items.Remove(checkBox2.Tag);
   }
   if (!checkBox3.Checked) 
   {
     listBox4.Items.Remove(checkBox3.Tag);
   }
}



Aucun commentaire:

Enregistrer un commentaire