创建文本框@ runtime ... [英] creating textboxes @ runtime...

查看:73
本文介绍了创建文本框@ runtime ...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以根据用户输入创建文本框@ runtime



1)文本框---获取用户输入。

2)按钮---创建文本框



i有一个用于获取用户输入的文本框...如果用户给出2个意思,那么我想动态创建两个文本框



提前致谢....

解决方案

当然。

 TextBox txt =  new  TextBox(); 
txt.ID = txtNew;
txt.Text = 这是一个新的文本框;
Form.Controls.Add(txt);





这是一个简单的例子,但你可以适应你的需求。




试试这个:



  private   void  button1_Click( object  sender,EventArgs e) 
{
AddDynamicTextBox( 5 );
}

public void AddDynamicTextBox( int numberOfTextBoxes)
{
for int i = 0 ; i < = numberOfTextBoxes; ++ i)
{
TextBox textBox = new TextBox();
textBox.Name = TextBox + i.ToString();
textBox.Text = TextBox + i.ToString();
textBox.Location = new Point( 20 ,i * 20 );
this .Controls.Add(textBox);
}
}





您将从输入中定义numberOfTextBoxes。您需要注意的一点是位置,如果您不给位置值,控件会将每个文本框添加到彼此的顶部,这样看起来只有一个文本框。



问候

Jegan


您好,



使用on按钮Click事件



TextBox TextBox1 = new TextBox();

TextBox1.ID =txt_1;



TextBox1.MaxLength = 50;



//添加风格

TextBox1.Style.Add (宽度,200px);



TextBox1.Width = 50;

this.Controls.Add(TextBox1);

Is it possible to create textboxes @ runtime based on user input

1)textbox--- to get the user input.
2)button--- to create the textboxes

i have a textbox for getting user input...if user give 2 means then i want to create dynamically two textboxes

Thanks in advance....

解决方案

Sure.

TextBox txt = new TextBox();
txt.ID = "txtNew";
txt.Text = "This is a new textbox";
Form.Controls.Add(txt);



That''s a simple example but you can adapt to your needs.


Hi,
Try this:

private void button1_Click(object sender, EventArgs e)
{
    AddDynamicTextBox(5);
}

public void AddDynamicTextBox(int numberOfTextBoxes)
{
    for (int i = 0; i <= numberOfTextBoxes; ++i)
    {
        TextBox textBox = new TextBox();
        textBox.Name = "TextBox" + i.ToString();
        textBox.Text = "TextBox" + i.ToString();
        textBox.Location = new Point(20, i * 20);
        this.Controls.Add(textBox);
    }
}



The "numberOfTextBoxes" you will defined from your input. One thing you need to be careful of is the location, if you do not give location value, the control will add each text box on top of each other so it will look like there is only one text box.

Regards
Jegan


Hi,

Use the on button Click event

TextBox TextBox1 = new TextBox();
TextBox1.ID = "txt_1" ;

TextBox1.MaxLength = 50;

//Add Style
TextBox1.Style.Add("width", "200px");

TextBox1.Width = 50;
this.Controls.Add(TextBox1);


这篇关于创建文本框@ runtime ...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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