如何将RadioButton单选框分组? Form窗体上面假如有10个RadioButton单选框,但是每次只能选中一个,我怎样将它们分成两组,每组5个,这样两个组就可以不受干扰,分别可以选择一个? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在c#中,同一个control中的中RadioButton将作为一组,所以你只需用两个容器将其分成两组就行了 必须将radioButton放在其它的button里面吗?还有没有其它的方法? 用GroupBox是最正统的做法了。 请见:http://community.csdn.net/Expert/topic/4207/4207530.xml?temp=.2681848 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()); }} rdlc 报表列不固定怎么布局 关于 窗体关闭按钮 继续求问正则表达式匹配表。 请教高手!timr`listvew`禁下拉滚动条! 非超级高手,无法解答,关于使用.net环境保护 win32程序,绝对创意 C#访问数据库的问题? 求正则表达式 VS2005的正则表达式替换 请问WMI可不可以跨网段进行控制啊? C#怎样判断一个输入的字符串是数值型? 如何封装数据库连接操作,以便以后每个页面调用 动态加载dll的问题!!! xml中有不常见字符,XmlDocument.load时出错
还有没有其它的方法?
用GroupBox是最正统的做法了。
http://community.csdn.net/Expert/topic/4207/4207530.xml?temp=.2681848
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());
}
}