动态添加文本框的文本 [英] dynamically added Textbox's text
本文介绍了动态添加文本框的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在单击按钮时动态地将文本框添加到面板(panel1)中
并想在按钮的lcick上检索其值(btnretrive)
但是会抛出一个异常,说panel1不包含任何控件.
在这个
Am adding a textbox to a panel(panel1) dynamically on click of a button add
And want to retrieve its value on lcick of a button (btnretrive)
but an exception is thrown saying panel1 doesnot contain any controls.
help me on this
推荐答案
上帮我,没有您的代码,很难准确地评论它的问题所在!相反,我将使用以下代码将文本框添加到面板中:
Without your code, it is difficult to comment accurately on what is wrong with it! Instead, I would use this code to add the textbox to my panel:
TextBox tb = new TextBox();
tb.Width = 100;
tb.Height = 50;
tb.Location = new Point(10,10);
tb.Text = "My New TextBox";
myPanel.Controls.Add(tb);
我将使用以下代码对其进行访问:
And I would use this code to access it:
foreach(Control c in myPanel.Controls)
{
TextBox tb = c as TextBox;
if (tb != null)
{
Control.WriteLine(tb.Text);
}
}
您在做什么与众不同?
此链接 [ ^ ]讨论了遍历控件的情况,并且可能为您提供帮助.
This link [^]discusses looping through controls and may be a help to you.
尝试此链接
链接[ ^ ]
try this Link
Link [^]
这篇关于动态添加文本框的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文