4
我尝试添加复选框为循环,当我输入3例如在文本框中,然后单击按钮它自动添加3复选框的形式 我试过这个代码,但只添加一个复选框如何添加循环控制
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;
//button2.UseVisualStyleBackColor = true;
this.Controls.Add(button2);
m++;
}
}
然后不要使用'm'作为'TabIndex'。 +1 –
感谢所有我真的把它们分开了,现在它工作 –