How do I get which radio button is checked from a groupbox?

后端 未结 5 1971
你的背包
你的背包 2020-12-09 16:52

I have these groupboxes:

\"Enter

I want to run some code according to checked

5条回答
  •  無奈伤痛
    2020-12-09 17:39

    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);
    

提交回复
热议问题