[英]C# - If A Radiobutton Selected In GroupBox, Unselect Other Radiobuttons In Other GroupBoxes
[英]Excluding the GroupBoxes that are inside another GroupBox
假設我有7個分組框,但其中一些還具有分組框,而有些則沒有。 現在,如果我要遍歷這7個分組框並對其應用某些內容,是否可以從該循環中排除那些子分組框?
用標記屬性或其他標記它們。
盡管我質疑實現的選擇(您可以使用多態性嗎?您到底想做什么?),但是有一個Parent屬性,例如
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);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.