private Control FindControl(Control parent, string controlName)
{
Control c = null;
foreach (Control ctrl in parent.Controls)
{
if (ctrl.GetType().ToString() == typeof(ToolStrip).ToString())
{
foreach (ToolStripItem item in ((ToolStrip)ctrl).Items)
{
if (item.GetType().ToString() == typeof(ToolStripButton).ToString())
{
if (item.Name.Equals(controlName))
{
c = item;
return c;
}
}
}
}
if (c == null)
c = FindControl(ctrl, controlName);
else
break;
}
return c;
}
private void button3_Click(object sender, EventArgs e)
{
Control c = FindControl(this, "toolStripButton1");
}
I've make the bold line for your idea. If you have carefully seen that, then you could also have solved it. Btw, let me know the results.