private static Control FindControlBackward(Control container, Control start) {
Control found = null;
if (start == null) {
found = FindFlatBackward(container, start);
}
else if (start != container) {
if (start.parent != null) {
found = FindFlatBackward(start.parent, start);
if (found == null) {
if (start.parent != container)
return start.parent;
return null;
}
}
}
if (found == null || start.parent == null)
found = start;
while (found != null && (found == container || (!((found is IContainerControl) && found.GetStyle(ControlStyles.ContainerControl))) &&
found.child_controls != null && found.child_controls.Count > 0)) {
// while (ctl.child_controls != null && ctl.child_controls.Count > 0 &&
// (ctl == this || (!((ctl is IContainerControl) && ctl.GetStyle(ControlStyles.ContainerControl))))) {
found = FindFlatBackward(found, null);
}
return found;
/*
Control found;
found = null;
if (start != null) {
found = FindFlatBackward(start.parent, start);
if (found == null) {
if (start.parent != container) {
return start.parent;
}
}
}
if (found == null) {
found = FindFlatBackward(container, start);
}
if (container != start) {
while ((found != null) && (!found.Contains(start)) && found.child_controls != null && found.child_controls.Count > 0 && !(found is IContainerControl)) {// || found.GetStyle(ControlStyles.ContainerControl))) {
found = FindControlBackward(found, null);
if (found != null) {
return found;
}
}
}
return found;
*/
}