如何判断20个RadioButton的其中一个checked为true 方法1:一个是把这20个放在一个group框里。这个就互斥了。再做一个变量来识记一下。方法2:放到arraylist之类的容器里。到时从头到尾判断一下。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你问的问题应该有两个方面:1.找出20个RadioButton中某个特定的RadioButton(如RadioButton1)的Checked属性是否为true,则直接判断即可: if RadioButton1.Checked==true { ...}2.找出20个RadioButton中Checked属性为true的是哪一个?则依次判断每一个RadioButton的Checked属性即可(如上),或构造一个包含所有RadioButton对象的集合,任何使用foreach 循环。 foreach(System.Windows.Forms.Control obj in this.Controls) { if(obj.GetType().Name.ToString()=="RadioButton") { //obj转换成RadioButton,再做判断 } } private string GetChkName(){ foreach(control ctrl in frm.Controls) { if(ctrl is RadioButton) { RadioButton rt=ctrl as RadioButton; if(rt.Checked) return rt.Name; } } return "";} 楼上非常对,得写一个Controls的控件集合,用foreach遍历 foreach(Control cmicCtl in this.Controls) { if(cmicCtl.GetType()==typeof(RadioButton)) { RadioButton cmicRdo=(RadioButton)cmicCtl; if(cmicRdo.Checked==true) { strCode=cmicRdo.Tag.ToString();//cmicRdo你要的控件 strLocation=cmicRdo.Text; break; } } } foreach(Control cmicCtl in this.Controls) { if(cmicCtl.GetType()==typeof(RadioButton)) { RadioButton cmicRdo=(RadioButton)cmicCtl; if(cmicRdo.Checked==true) { strCode=cmicRdo.Tag.ToString();//cmicRdo你要的控件 strLocation=cmicRdo.Text; break; } } } 关于继承与构造函数的一个问题 winform c/s程序和数据库打包问题 商品大类 和小类的div如何使重叠的border为0 vs2008 创建兼容win7的application应用程序 打包的时候,加不进要打包的文件? CLR以后会不会升级呢? C#上传文件到FTP服务器,求解!在线等,多谢! 思归请进:进程中有两个DLLHOST.EXE,怎样KILL其中的一个? 一个很奇怪的问题(关于类型转换的) 探讨用ADO.NET编程的方法实现数据访问功能 《C#技术内幕》这本书怎么样,大家来评一下, 或给新手推荐本好书啊 C#连接远程数据库。。。急
1.找出20个RadioButton中某个特定的RadioButton(如RadioButton1)的Checked属性是否为true,则直接判断即可:
if RadioButton1.Checked==true
{ ...}
2.找出20个RadioButton中Checked属性为true的是哪一个?则依次判断每一个RadioButton的Checked属性即可(如上),或构造一个包含所有RadioButton对象的集合,任何使用foreach 循环。
{
if(obj.GetType().Name.ToString()=="RadioButton")
{
//obj转换成RadioButton,再做判断
}
}
private string GetChkName(){
foreach(control ctrl in frm.Controls)
{
if(ctrl is RadioButton)
{
RadioButton rt=ctrl as RadioButton;
if(rt.Checked)
return rt.Name;
}
}
return "";
}
{
if(cmicCtl.GetType()==typeof(RadioButton))
{
RadioButton cmicRdo=(RadioButton)cmicCtl;
if(cmicRdo.Checked==true)
{
strCode=cmicRdo.Tag.ToString();//cmicRdo你要的控件
strLocation=cmicRdo.Text;
break;
}
}
}
{
if(cmicCtl.GetType()==typeof(RadioButton))
{
RadioButton cmicRdo=(RadioButton)cmicCtl;
if(cmicRdo.Checked==true)
{
strCode=cmicRdo.Tag.ToString();//cmicRdo你要的控件
strLocation=cmicRdo.Text;
break;
}
}
}