简体   繁体   中英

Excluding the GroupBoxes that are inside another GroupBox

Let's say I have 7 group boxes but some of them also have group box inside them and some do not. now if I want to iterate through those 7 group boxes and apply something to them, is there a way that I can exclude those Child group boxes from this loop?

用标记属性或其他标记它们。

though i question the choice of implementation (can you use polymorphism instead? what exactly are you trying to do?), there is a Parent property, eg

void soSomething(Control ctrl)
{
    if (ctrl is GroupBox && (ctrl.Parent is null || !(ctrl.Parent is GroupBox)))
    {
         //do something here
    }
    foreach(Control child in ctrl.Controls)
    {
        doSomething(child);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM