动态文字框 [英] dynamic text boxes

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

问题描述

在我的项目中,我必须插入供应商项目信息.

为此,我需要动态生成文本框.
最初,我应该有一行四个文本框和一个添加按钮,用于生成新行的文本框.

我还必须在这些文本框中进行一些计算:

第4个文本框的值= 2个文本框值+第3个文本框

请帮我完成这项任务!

谢谢!

In my project I have to insert vendor item information.

For that I need dynamic generation of textboxes.
Initially I should have a row of four textboxes and one add button for generating new row of textboxes.

I also have to do some calculations in those textboxes:

Value of 4th textbox = 2textbox value + 3rd textbox

Please help me with this task!

Thank you!

推荐答案

下面是动态创建文本框的代码:

Well here is a code to dynamically create textboxes:

//On the click event of the button , Write this:

 TextBox myNewTextBox=new TextBox();

 myNewTextBox.Text=String.Concat(TextBox2.Text,TextBox3.Text);
 // Assuming you have a panel pnl
 pnl.Controls.Add(myNewTextBox);


第四个TextBox的值应该在一个或多个会影响它的TextBox的TextChanged事件中设置. br/>
添加按钮的Click事件中,执行以下操作:

步骤1.创建新的TextBoxes:
The value of the fourth TextBox should be set in the TextChanged event of one or more of the TextBoxes that will effect it.

In the Add button''s Click event, do the following:

Step 1. Create new TextBoxes:
TextBox[] newRow = new TextBox[]{
     new TextBox(),
     new TextBox(),
     new TextBox(),
     new TextBox()
}



步骤2.调整每个文本框的属性以适合您的显示需求:



Step 2. Adjust the properties on each of the TextBoxes to fit your display needs:

newRow[0].Location = new Point(x,y);
newRow[0].Size = new Size(w,h);
newRow[0].Visible = true;
...etc.



步骤3.将事件处理程序挂接到TextBoxes(对于最初的四个TextBoxes,这些事件处理程序应该已经存在):



Step 3. Hook the event handlers to the TextBoxes (these event handlers should already exist for the initial four TextBoxes):

newRow[0].TextChanged += new TextChangedEventHandler(TextBox1_TextChanged);
newRow[1].TextChanged += new TextChangedEventHandler(TextBox2_TextChanged);
...etc.



步骤4.添加到表单/控件:



Step 4. Add to form/control:

form1.Controls.AddRange(newRow);


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

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