且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在.net windows app中动态添加控件列表

更新时间:2022-10-23 11:34:26

首先,你不能用它名称,但一次..在您的代码中,
 int count = 1; 
string name =textBox+ count.ToString();
TextBox name = new TextBox();



name 使用两次...



并且,试试这个作为你的解决方案..

 int count = 1; 
string str =textBox+ count.ToString();
TextBox nameTxt = new TextBox();
nameTxt.Text = str;


aam developing a windows app, i want that on clicking a button textboxes will be created with names textBox1,textBox2,textBox3....i am able to create textboxes and add it form, but i want the names to be dynamic e.g
int count=1;
string name="textBox"+count.ToString();
TextBox name=new TextBox();
But its not working........please help

First thing, you can''t use same name but once.. In your code,
int count=1;
string name="textBox"+count.ToString();
TextBox name=new TextBox();


name is used twice...

and, try this as your solution..

int count=1;
string str="textBox"+count.ToString();
TextBox nameTxt=new TextBox();
nameTxt.Text = str ;