I'm sorry if this seems n00bish, but I have been searching for this for a few days now. I am attempting to dynamically add checkboxes to a windows form; however, only one checkbox appears on the form. Here is my code:
for (int i = 0; i < 10; i++)
{
box = new CheckBox();
box.Tag = i.ToString();
box.Text = "a";
box.AutoSize = true;
box.Location = new Point(10, i + 10);
Main.Controls.Add(box);
}
As you can see I am adding the checkboxes via a for loop. I have tried messing with the location and enabling autosize in case they were somehow overlapping. The result is a single checkbox with text "a".
Actually you already created a CheckBox
but within the same point.
CheckBox box;
for (int i = 0; i < 10; i++)
{
box = new CheckBox();
box.Tag = i.ToString();
box.Text = "a";
box.AutoSize = true;
box.Location = new Point(10, i * 50); //vertical
//box.Location = new Point(i * 50, 10); //horizontal
this.Controls.Add(box);
}
In this case with help of dynamically assign Name property how to achive checkbox.checked property , in some other action like submit button. how can i get all check box is checked and which is created in loop?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With