读书人

怎么取得动态控件中的值

发布时间: 2011-12-25 23:21:20 作者: rapoo

如何取得动态控件中的值?
我通过如下方法在界面上循环显示一组textbox
列举其中一个
Dim textbox As New TextBox
textbox.Name = "test " + cstr(i) 'i是循环变量

然后我想在其他方法中取得这些test的textbox中的值
这里的代码该怎么写?
比如我要取test1中的value,直接写test1.text肯定不行,用CType好像也不对

请高手帮忙。

[解决办法]
private void button1_Click(object sender, EventArgs e)
{
this.Text = FindControl(this, "textBox1 ").Text;
}

private System.Windows.Forms.Control FindControl(System.Windows.Forms.Control control, string strName)
{
foreach (System.Windows.Forms.Control subControl in control.Controls)
{
if (subControl.Name == strName)
{
return subControl;
}
return FindControl(subControl, strName);
}
return null;
}

读书人网 >VB Dotnet

热点推荐