首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

如何透过string形式的名称来访问某个控件

2013-12-02 
怎么透过string形式的名称来访问某个控件?例如:string theNametextBox1theName.Text......... // 目

怎么透过string形式的名称来访问某个控件?
例如:
string theName="textBox1";
theName.Text=.........; // 目的是想访问 textBox1 
[解决办法]

 string theName = "textBox1";

            foreach (var item in this.Controls.Find(theName, false))
            {
                if (item is TextBox)
                {
                    TextBox tb = item as TextBox;
                    MessageBox.Show(tb.Text);
                    break;
                }
            }

热点排行