I am trying to loop through all ToolStripButtons and find all ToolStripButtons. My Code is:
private ToolStripItem FindControl(ToolStripButton parent, string controlName)
{
ToolStripButton c = null;
foreach (ToolStrip ctrl in parent.Owner.Items.ToString())
{
if (ctrl.GetType().ToString() == typeof(ToolStrip).ToString())
{
foreach (ToolStripButton item in ((ToolStripButton)ctrl).OwnerItem.Name)
{
if (item.GetType().ToString() == typeof(ToolStripButton).ToString())
{
if (item.Name.Equals(controlName))
{
//c = item.GetType().ToString() =typeof(ToolStripButton).ToString();
return item;
}
}
}
}
if (c == null)
{
c = FindControl(parent.GetType().ToString() == typeof(ToolStripButton).ToString(), parent.Name);
}
else
{
break;
}
}
return c;
}
But it doesn't yield expected result.enter image description here