如何在c sharp中动态创建文本框? [英] How to create Textbox dynamically in c sharp ?

查看:201
本文介绍了如何在c sharp中动态创建文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在每个textbox_leave事件的Windows窗体中动态创建Textbox。

例如..



动态创建

Textbox1

离开事件火灾on textbox1

Texbox2已创建

在文本框2上保持事件触发

textbox3已创建







n创建的文本框数量



无法创建的文本框,直到用户弃用我想要离开事件。

I want to create Textbox's dynamically in my windows form with every textbox_leave event.
For example ..

created dynamically
Textbox1
leave event fire on textbox1
Texbox2 is created
leave event fire on textbox2
textbox3 is created
.
.
.
n number of textbox created

unmlimited textboxs is created until user don't want to fire leave event.

推荐答案

private void btnText1_Click(object sender, EventArgs e)
{
     TextBox txtBox2 = new TextBox();
     txtBox2.Name = "two";
     txtBox2.Text = "two";
     Controls.Add(txtBox);
}





您也可以将事件添加到动态文本框中。



You can add events to the dynamic textbox as well.


先生,有一个好朋友你的几乎忘了访问他,然后在这里提问。他的名字是 Google :笑试试此链接将帮助您探索答案 http://www.lmgtfy.com/?q=How+to+create+Textbox+dynamically+in+c+sharp [ ^ ]
sir, there is a good friend of your's and you almost forgot to visit him before asking the question here. His name is "Google" :laugh try this link will help you in exploring answers http://www.lmgtfy.com/?q=How+to+create+Textbox+dynamically+in+c+sharp[^]


TextBox[] txtTeamNames = new TextBox[teams];
for (int i = 0; i < txtTeamNames.Length; i++) {
  var txt = new TextBox();
  txtTeamNames[i] = txt;
  txt.Name = name;
  txt.Text = name;
  txt.Location = new Point(172, 32 + (i * 28));
  txt.Visible = true;
}


这篇关于如何在c sharp中动态创建文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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