成人英语培训网 加入收藏  -  设为首页
您的位置:成人英语培训网 > 旅游英语 > 正文
c#判断radioButtom是否选中
c#判断radioButtom是否选中
提示:

c#判断radioButtom是否选中

不知道你的每一个题目用的是什么控件做容器的。假设你每个题目的label和radil都是放在一个Panel里的。所有的这些Panel都是放在Form窗体里的。
判断Radio选中状态:
private bool CheckRadioSelected()
{
foreach(Control contain in this.Controls)
{
Panel pnl = contain as Panel;
if(pnl != null)//找到一个Panel
{
bool isSelected = false;
foreach(Control con in pnl.Controls)
{
RadioButton rdb = con as RadioButton;
if(rdb != null && rdb.Checked)
{
isSelected = true;
break;
}
}
if(!isSelected)
{
return false;//有某个题目的radio没选中
}
}
}
return true;//所有题目都选过了
}

C#怎么按下面的用法使用radioButton按钮?
提示:

C#怎么按下面的用法使用radioButton按钮?

用foreach 遍历你窗体的的所有RadioButton控件
//第一种情况:RadioButton在窗体上
foreach (Control c in this.Controls)
{
RadioButton btn = c as RadioButton;
if (btn != null)
{
if (btn.Text == "确定")
{
//进行赋值 a="a";
}

//第二种情况:RadioButton在panel等容器里面
Panel p = c as Panel;
if (p != null)
{
foreach (Control cc in p.Controls)
{
RadioButton btn = c as RadioButton;
if (c_btn != null)
{
if (c_btn.Text == "确定")
{
//进行赋值 a="a";
}
}

}
}
}