How to find a Control by it's name in c# Windows

时间:2016-12-02 05:18:05

标签: c# .net winforms

I have some controls in my form inside a panel. I want to get value of any control if I know the name of that control which is Inside that Panel. So I did following effort....

foreach (Control ch in pnl.Controls)
{
     if (ch.Name == "ControlName")
          MessageBox.Show(ch.Text);
}

But this code loop through all the controls inside that panel, that's not my exact requirement. I want to find that control without any loop.

May be my question looks like duplicate of this post, but that post is helpful when you already know that your desired control is TextBox. What if I don't know the type of my control ?

0 个答案:

没有答案