How to get value of Radio Buttons?

后端 未结 7 1355
自闭症患者
自闭症患者 2020-12-30 05:05

I have a group box contains radio buttons eg.

o Male

o Female

i want my code to get the sel

7条回答
  •  生来不讨喜
    2020-12-30 05:40

    Windows Forms

    For cases where there are multiple radio buttons to check, this function is very compact:

    /// 
    /// Get the value of the radio button that is checked.
    /// 
    /// The radio buttons to look through
    /// The name of the radio button that is checked
    public static string GetCheckedRadioButton(params RadioButton[] radioButtons)
    {
        // Look at each button, returning the text of the one that is checked.
        foreach (RadioButton button in radioButtons)
        {
            if (button.Checked)
                return button.Text;
        }
        return null;
    }
    

提交回复
热议问题