mardi 23 août 2016

Create checkbox dynamiclly and detect checked

I am creating a five checkboxes dynamiclly with a for loop inside a GroupBox. now, they were created dynamiclly, so I don't know how can I make a ChangeCheck method attached to them?

All those checkoxes are related so what I am trying to do is something like that:

  1. create 5 checkboxes dynamiclly
  2. add each checkbox to a list
  3. when a specific checkbox in the list is on trigger a method.

this is how I create the checkboxes:

for (int i = 0; i < 5; i++)
{
    CheckBox chk = new CheckBox();
    chk.size = new Size(10, 10);
    chk.Top = 10
    chk.Left = 20
    chk.Text = i.ToString();
    group_box_name.controls.Add(chk);
}

Now, how can I detect which checkbox was on/off?




Aucun commentaire:

Enregistrer un commentaire