Form窗体上面假如有10个RadioButton单选框,但是每次只能选中一个,我怎样将它们分成两组,每组5个,这样两个组就可以不受干扰,分别可以选择一个?

解决方案 »

  1.   

    在c#中,同一个control中的中RadioButton将作为一组,所以你只需用两个容器将其分成两组就行了
      

  2.   

    必须将radioButton放在其它的button里面吗?
    还有没有其它的方法?
      

  3.   


    用GroupBox是最正统的做法了。
      

  4.   

    请见:
    http://community.csdn.net/Expert/topic/4207/4207530.xml?temp=.2681848
      

  5.   

    using System;
    using System.Windows.Forms;class Test : Form
    {
      RadioButton [] A = new RadioButton [5];
      RadioButton [] B = new RadioButton [5];  Test()
      {
        for (int i = 0; i < A.Length; i++)
        {
          A[i]             = new RadioButton();
          A[i].Parent      = this;
          A[i].Left        = i*40+10;
          A[i].Width       = 35;
          A[i].Text        = "A" + (i+1);
          A[i].AutoCheck   = false;
          A[i].Click      += new EventHandler(AClick);
        }
        for (int i = 0; i < B.Length; i++)
        {
          B[i]             = new RadioButton();
          B[i].Parent      = this;
          B[i].Top         = 40;
          B[i].Left        = i*40+10;
          B[i].Width       = 35;
          B[i].Text        = "B" + (i+1);
          B[i].AutoCheck   = false;
          B[i].Click      += new EventHandler(BClick);
        }
      }  void AClick(object sender, EventArgs ea)
      {
        foreach (RadioButton ctl in A)
        {
          ctl.Checked = ctl == (RadioButton)sender;
        }
      }  void BClick(object sender, EventArgs ea)
      {
        foreach (RadioButton ctl in B)
        {
          ctl.Checked = ctl == (RadioButton)sender;
        }
      }  static void Main()
      {
        Application.Run(new Test());
      }
    }