我正在尝试编写代码以创建动态文本框。c#以第二种形式创建动态文本框
我有功能类,并在我指定的程序第二种形式ProductForm.cs
我想要做的是与我Function.cs
名为GetSpecs
功能,比内GetSpecs
我要调用一个函数读取一些数据另一类,并将数据发送到我的其他功能类ProductForm.cs
。
我在最后得到空白表单。
我GetSpecs
功能的一部分:
private String GetSpecs(String webData)
{
......
ProductForm form2 = new ProductForm();
form2.CreateTextBox(n);
}
ProductForm.cs
public void CreateTextBox(int i)
{
ProductForm form2 = new ProductForm();
form2.Visible = true;
form2.Activate();
int x = 10;
int y = 10;
int width = 100;
int height = 20;
for (int n = 0; n < i; n++)
{
for (int row = 0; row < 4; row++)
{
String name = "txtBox_" + row.ToString();
TextBox tb = new TextBox();
tb.Name = name;
tb.Location = new Point(x, y);
tb.Height = height;
tb.Width = width + row * 2;
x += 25 + row * 2;
this.Controls.Add(tb);
}
y += 25;
}
}
我得到ProductForm的空白表单。文本框不会创建,或者我看不到它们。
如果我把文本框里面
private void ProductForm_Load(object sender, EventArgs e)
我可以看到文本框。
非常感谢。你是对的。它解决了我现在正在工作的问题! –