I am trying to add a checkbox for a loop, which when I enter 3, for example, in a text box, and click a button, it automatically adds 3 checkboxes in the form I tried this code, but added only one checkbox
private void button1_Click(object sender, EventArgs e) { int x = Convert.ToInt32(textBox1.Text); int m = 1; for (int i = 0; i < x; i++) { CheckBox button2 = new System.Windows.Forms.CheckBox(); button2.Location = new System.Drawing.Point(5, m); button2.Name = "button2 "+ m.ToString(); button2.Size = new System.Drawing.Size(51, 23); button2.TabIndex = m;
source share