Is something like that you want??
private object FindObject (string strObjectName, string strObjectType)
{
foreach (Control controlObj in this.Controls)
{
if ((controlObj.GetType().ToString() == strObjectType) && (controlObj.Name
== strObjectName))
{
return controlObj;
}
}
return null;
}
private void button1_Click(object sender, System.EventArgs e)
{
object obj = FindObject (textBox1.Text, "System.Windows.Forms.Label");
if (obj != null)
{
MessageBox.Show(((Label)obj).Text);
}
else
{
MessageBox.Show("object not found");
}
}
"Rob Lykens" wrote:
I am wondering if anyone has done something like this? I want to find a label
based on the passed in information. It would be awesome to find something
like this:
private void myvoid (int i)
{
string lbl = "label" + i;
Label mylabel = (Label)lbl;
lbl.Text = "I have found the label on my form by this method!";
}
Anyone got a method?
Thanks!