我目前正在编写一个从 xml 动态创建表单的 C# 程序。当前的 xml 包含我需要的 67 个字符串。但是,当 for 循环达到 34 或 35 时,它会返回 null。代码如下
for(int x =0; x < 67: x++){
CheckBox sue = (CheckBox)GetChildAtPoint(new Point(760, loc));
loc = loc + 20;
}
我已经手动检查了表格,那里有一些东西,我正在使用最新的框架。我还发布了用于动态发布复选框和标签的代码。
for (int x = 0; x < cnt; x++)
{
/*creating the form*/
String edit = "e1";
String template = "t1";
this.Controls.Add(new Label() {Text = data[x], Width=540, Name = x.ToString(), Location = new Point(20, loc) });
this.Controls.Add(new CheckBox() {Checked = true, Width = 20, Name = edit, Location = new Point(560, loc) });
this.Controls.Add(new CheckBox(){ Width = 20, Name = template, Location = new Point(760, loc)});
loc = loc + 20;
}
在我看来,唯一合乎逻辑的事情是 GetChildAtPoint 是有限制的,而 xml 格式是企业网站的标准 site.xml 文件。无论如何完成这将对我有很大帮助。