I have these groupboxes:
I want to run some code according to checked
You should take some look at the CheckedChanged
event to register the corresponding event handler and store the Checked
radio button state in some variable. However, I would like to use LINQ here just because you have just some RadioButtons
which makes the cost of looping acceptable:
var checkedRadio = new []{groupBox1, groupBox2}
.SelectMany(g=>g.Controls.OfType()
.Where(r=>r.Checked))
// Print name
foreach(var c in checkedRadio)
System.Diagnostics.Debug.Print(c.Name);