单击按钮时动态创建文本框以及如何处理动态创建控件的事件 [英] dynamically creating textbox on button click and how to handle event of dynamically create control

查看:88
本文介绍了单击按钮时动态创建文本框以及如何处理动态创建控件的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在从事c#.net项目.我需要在单击添加按钮时动态创建文本框.以及如何处理动态创建的文本框的事件.

如果有任何疑问,如果您不清楚我的意思,请提出.这很紧急.请帮忙!!!

请给我建议,并帮助我进行这些工作.

希望得到任何帮助,我们将感到非常高兴和感谢.

在此先感谢..

Hello,

I am working on c#.net project. I need to create textbox dynamically on clicking the Add button. And how to handle events of dynamically created textbox.

If any question, if you did not get my point clear than please ask. Its urgent. Please Help!!!

Please give me suggestion and help me to work on these.

It would be pleased and appreciated to any help

Thanks in advance..

推荐答案

请参考:
创建动态文本框控件 [在vb.net中创建动态文本框 [如何在vb.net中处理动态创建的TextBoxControl的事件2008 [ ^ ]
Please refer:
Creating Dynamic TextBox Controls[^]
Create dynamic Textbox in vb.net[^]

Have a look on similar answer, this will surely solve your problem:
How to Handel Events of dynamically created TextBoxControl in vb.net 2008[^]


受保护的无效btnAdd_Click(对象发送者,EventArgs e)
{

//int cnt = FindOccurence("txtDynamic");

//CreateTextBox("txtDynamic-" + Convert.ToString(cnt + 1));

标签lblmilestone = new Label();
lblmilestone.Name ="lblmilest" + c;
lblmilestone.Text =里程碑" + c;
lblmilestone.Location =新的System.Drawing.Point(20,18 +(20 * c));
lblmilestone.Size =新的System.Drawing.Size(100,22);
this.panel1.Controls.Add(lblmilestone);

TextBox txtRun = new TextBox();
txtRun.Name ="txtDynamic" + c;
txtRun.Location =新的System.Drawing.Point(129,15 +(20 * c));
txtRun.Size = new System.Drawing.Size(200,25);
this.panel1.Controls.Add(txtRun);

TextBox txtRun1 =新的TextBox();
txtRun1.Name ="txtDynamicx" + c ++;
txtRun1.Location =新的System.Drawing.Point(373,-5 +(20 * c));
txtRun1.Size =新的System.Drawing.Size(100,25);
this.panel1.Controls.Add(txtRun1);

}
protected void btnAdd_Click(object sender, EventArgs e)
{

//int cnt = FindOccurence("txtDynamic");

//CreateTextBox("txtDynamic-" + Convert.ToString(cnt + 1));

Label lblmilestone = new Label();
lblmilestone.Name = "lblmilest" + c;
lblmilestone.Text = "Milestone" + c;
lblmilestone.Location = new System.Drawing.Point(20, 18 + (20 * c));
lblmilestone.Size = new System.Drawing.Size(100, 22);
this.panel1.Controls.Add(lblmilestone);

TextBox txtRun = new TextBox();
txtRun.Name = "txtDynamic" + c;
txtRun.Location = new System.Drawing.Point(129, 15 + (20 * c));
txtRun.Size = new System.Drawing.Size(200, 25);
this.panel1.Controls.Add(txtRun);

TextBox txtRun1 = new TextBox();
txtRun1.Name = "txtDynamicx" + c++;
txtRun1.Location = new System.Drawing.Point(373, -5 + (20 * c));
txtRun1.Size = new System.Drawing.Size(100, 25);
this.panel1.Controls.Add(txtRun1);

}


这篇关于单击按钮时动态创建文本框以及如何处理动态创建控件的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆