If you just want to know which control is in front of the parent collection, follow these steps:
private bool IsControlAtFront(Control control) { return control.Parent.Controls.GetChildIndex(control) == 0; }
Note that Z-Index 0 is the topmost one , the larger the number lower down the hierarchy.
In addition, this code above currently only works for a control inside an individual parent. You will also need to recursively verify that the parent is also at z-index 0.
This will work for any control anywhere on the form:
private bool IsControlAtFront(Control control) { while (control.Parent != null) { if (control.Parent.Controls.GetChildIndex(control) == 0) { control = control.Parent; if (control.Parent == null) { return true; } } else { return false; } } return false; }
GenericTypeTea
source share