C# winform 单选框

        private void radioButton_Click(object sender, EventArgs e)
        {
            RadioButton radioButton = (RadioButton)sender;

            for (int i = 0; i < radioGroup.Controls.Count; i++)
            {
                #region 1.一个单选框被选中时,另一个改变状态
                if (radioButton != radioGroup.Controls[i])
                {
                    (radioGroup.Controls[i] as RadioButton).Checked = false;
                }
                else
                {
                    state = i;
                }
                #endregion
            }


        }
            foreach (RadioButton item in radioGroup.Controls)
            {
                item.Click += new EventHandler(radioButton_Click!); 
            }

            (radioGroup.Controls[0] as RadioButton)!.Checked = true;

你可能感兴趣的:(C#,c#,开发语言)