从 Windows 窗体控件中按名称查找控件

问题描述:

我有一个文本框名称列表,我想按名称查找控件.怎么可能?

I have a list of my textbox names, and I want to find a control by name. How is it possible?

使用 Control.ControlCollection.Find.

TextBox tbx = this.Controls.Find("textBox1", true).FirstOrDefault() as TextBox;
tbx.Text = "found!";

编辑提问者:

Control[] tbxs = this.Controls.Find(txtbox_and_message[0,0], true);
if (tbxs != null && tbxs.Length > 0)
{
    tbxs[0].Text = "Found!";
}