日期:2014-05-17  浏览次数:21059 次

在线请教--如何取groupbox中radiobutton的值??
如图:



------解决方案--------------------
给了第一个示例,后面的类似。
private string SearchCheckedRadioButton(Control.ControlCollection controlCllection)
        {
            foreach (var item in controlCllection)
            {
                if (item is RadioButton)
                {
                    RadioButton radioButton = item as RadioButton;
                    if (radioButton.Checked)
                    {
                        return radioButton.Text.Trim();
                    }
                }
            }
            return null;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int num1 = 0;
            string value = SearchCheckedRadioButton(groupBox1.Controls);
            switch (value)
            {
                case "0-10":
                    num1 = new Random().Next(0, 10);
                    break;
                case "0-20":
                    num1 = new Random().Next(0, 20);
                    break;
                case&nb