如何将RadioButton单选框分组?

chenshi 2005-08-06 09:45:21
Form窗体上面假如有10个RadioButton单选框,但是每次只能选中一个,我怎样将它们分成两组,每组5个,这样两个组就可以不受干扰,分别可以选择一个?
...全文
5068 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
wtoeb 2005-11-29
  • 打赏
  • 举报
回复
不错。
wsh236 2005-08-14
  • 打赏
  • 举报
回复
GroupBox最常用。最方便
chenshi 2005-08-14
  • 打赏
  • 举报
回复
必须将radioButton放在其它的button里面吗?
还有没有其它的方法?
manuever 2005-08-14
  • 打赏
  • 举报
回复
一般用GroupBox就行了。
wuyi8808 2005-08-14
  • 打赏
  • 举报
回复
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());
}
}
wuyi8808 2005-08-14
  • 打赏
  • 举报
回复
请见:
http://community.csdn.net/Expert/topic/4207/4207530.xml?temp=.2681848
uoyevoli 2005-08-14
  • 打赏
  • 举报
回复

用GroupBox是最正统的做法了。
lljfl 2005-08-08
  • 打赏
  • 举报
回复
在c#中,同一个control中的中RadioButton将作为一组,所以你只需用两个容器将其分成两组就行了
conrad_wan 2005-08-08
  • 打赏
  • 举报
回复
我一般用GroupBox.
Aallonlin 2005-08-08
  • 打赏
  • 举报
回复
用Panel或groupBox进行分组
caoyuechun 2005-08-08
  • 打赏
  • 举报
回复
用groupBox进行分组

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧