正如您在标题中看到的那样,我使用以下代码创建动态复选框:
private void create_checks(int nr, string name)
{
checkBox[nr] = new CheckBox();
checkBox[nr].Size = new Size(20, 43);
checkBox[nr].Name = name;
checkBox[nr].Text = name;
checkBox[nr].Location = new Point(40, 20 + (nr * 20));
this.Controls.Add(checkBox[nr]);
}
但是复选框没有文字,有人可以帮助我吗?
答案 0 :(得分:0)
增加with:
checkBox[nr] = new CheckBox();
checkBox[nr].Size = new Size(120, 43);
checkBox[nr].Name = name;
checkBox[nr].Text = name;
checkBox[nr].Location = new Point(40, 20 + (nr * 20));
frm.Controls.Add(checkBox[nr]);