Hi,
I want to trace all the parent controls of a control (e.g) if i have a form which contains panel which in turn contains another panel which contains button, i want to trace all the parents(form,panel,panel) from button how to do that?
Hi,
I want to trace all the parent controls of a control (e.g) if i have a form which contains panel which in turn contains another panel which contains button, i want to trace all the parents(form,panel,panel) from button how to do that?
The property Parent (inherited on every control from Control.Parent) provides access to the parent control. One can follow these references all the way up to the top-level Form.
You can try something like
private List<Control> FindParentList(Control control)
{
List<Control> retVal = new List<Control>();
Control c = control;
while (c.Parent != null)
{
Control parent = c.Parent;
retVal.Add(parent);
c = parent;
}
return retVal;
}
And to call the method use
List<Control> parentList = FindParentList(button1);