GroupBox包含控件,如何获取这些控件的名称?

Mic*_*ael 5 .net c# winforms

我在我的表单页面(WinForms)上使用GroupBox控件.

GroupBox包含五个控件(RadioButtons).

知道怎样才能获得GroupBox Control中控件的名称和状态?

Tim*_*ter 14

您可以使用在GroupBox中Enumerable.OfType查找和转换您RadioButtons:

var radioButtons = groupBox1.Controls.OfType<RadioButton>();
foreach (RadioButton rb in radioButtons)
{
    bool state = rb.Checked;
    string name = rb.Name;
}
Run Code Online (Sandbox Code Playgroud)