method 1:
make TextBox tb as a member varialbe of your formmethod 2:
在另外一个按钮的单击事件中, look through pan.Controls collection:foreach (Control c in pan.Controls)
{
if (c is TextBox)
{
MessageBox.Show(((TextBox)c).Text);
}
}
method 3:
if you have a lot of dynamic controls, try something likeclass YourForm : Form
{
//member variable
Hashtable m_ht = new Hashtable();...
TextBox tb = new TextBox();
tb.Name = "mytb";
m_ht[tb.Name] = tb;pan.Controls.Add(tb);
Label lb = new Label();
pan.Controls.Add(lb);在另外一个按钮的单击事件中,
TextBox tb = (TextBox)m_ht["mytb"];
MessageBox.Show(tb.Text);
make TextBox tb as a member varialbe of your formmethod 2:
在另外一个按钮的单击事件中, look through pan.Controls collection:foreach (Control c in pan.Controls)
{
if (c is TextBox)
{
MessageBox.Show(((TextBox)c).Text);
}
}
method 3:
if you have a lot of dynamic controls, try something likeclass YourForm : Form
{
//member variable
Hashtable m_ht = new Hashtable();...
TextBox tb = new TextBox();
tb.Name = "mytb";
m_ht[tb.Name] = tb;pan.Controls.Add(tb);
Label lb = new Label();
pan.Controls.Add(lb);在另外一个按钮的单击事件中,
TextBox tb = (TextBox)m_ht["mytb"];
MessageBox.Show(tb.Text);
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货