我在groupBox里添加了5个radioButton.它有没有一个属性指明选了那个radioButton? 这样可以减少写radioButton 的 checked .

解决方案 »

  1.   

    你可以自己写一个usercontrol来完成你要的功能
      

  2.   

    先写1个radioButton的单击事件
    完了把其他的单击事件指定到那个写好的事件里
    通过判断sender来执行各自的方法
      

  3.   

    for (int i = 0; i < groupBox1.Controls.Count; i++)//将它们放入容器里
                {
                    if (groupBox1.Controls[i] is RadioButton)
                    {
                        RadioButton temp = (RadioButton) groupBox1.Controls[i];
                        if (temp.Checked)//判断是否选中
                           textBox2.Text= temp.Name;//这个可以自己改
                    }
                }
      

  4.   

    写一个循环 遍历整个groupBox1就可以了!
      

  5.   

    窗体设计器生成的代码
    // 
    // radioButton1
    // 
    this.radioButton1.Location = new System.Drawing.Point(48, 24);
    this.radioButton1.Name = "radioButton1";
    this.radioButton1.Size = new System.Drawing.Size(88, 16);
    this.radioButton1.TabIndex = 0;
    this.radioButton1.Text = "radioButton1";
    this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
    // 
    // radioButton2
    // 
    this.radioButton2.Location = new System.Drawing.Point(48, 56);
    this.radioButton2.Name = "radioButton2";
    this.radioButton2.Size = new System.Drawing.Size(88, 16);
    this.radioButton2.TabIndex = 1;
    this.radioButton2.Text = "radioButton2";
    this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);事件中写
    private void radioButton1_CheckedChanged(object sender, System.EventArgs e)
    {
    if (sender.Equals(radioButton1))
    {
    textBox1.Text = "1";
    }
    if (sender.Equals(radioButton2))
    {
    textBox1.Text = "2";
    }
    }
      

  6.   

    谢谢 AhJo(AhJo) 和 david_anwei :)
      

  7.   

    我支持david的方法
    简单明了
      

  8.   

    同意AhJo(AhJo):
    “先写1个radioButton的单击事件
    完了把其他的单击事件指定到那个写好的事件里
    通过判断sender来执行各自的方法”没有必要写什么循环来遍历,浪费时间。
    给你参数(object sender, System.EventArgs e)就是给你用的