简体   繁体   中英

How Can I get by simple code the Checked RadioButton From Group of RadioButtons Located in same panel in C#?

I've a C# Windows Form Application that contains multiple Panels , each panel contains group of Radio Buttons.Is There a simple way to get just the checked RadioButton by code instead of checking every Radio Button in each group whether it is checked or not ? please help. Thanks

Try this:

foreach(Control control in panel.Controls)
{
    RadioButton radioButton = control as RadioButton;
    if (radioButton != null && radioButton.Checked)
        return radioButton;
}

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