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

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

I have these groupboxes:

\"Enter

I want to run some code according to checked

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-09 17:45

    In my opinion, it's better if you use RadioGroup instead of GroupBox. If you use radioGroup, you can always find the selected item easily like this:

    radioGroup.selectedIndex;
    

    If you design using Windows Forms, I suggest to implement RadioGroup behavior like this (please note that my code is in Java):

    for (Component comp:groupBox1.components) {
        if (((RadioButton)comp).selected)
            return ((RadioButton)comp).value;
    }
    

    You can put this code block in a method to return selected radioButton value, and then you can use this value in your SWITCH part.

提交回复
热议问题