日期:2014-05-18 浏览次数:21161 次
foreach (var it1 in this.Controls)
{
GroupBox gbx;
if ((gbx = it1 as GroupBox) != null)
{
foreach (var it2 in gbx.Controls)
{
RadioButton rbtn;
if ((rbtn = it2 as RadioButton) != null)
{
rbtn.Click += new EventHandler(rbtn_Click);
}
}
}
}
private void rbtn_Click(object sender, EventArgs e)
{
RadioButton rbtn = (RadioButton)sender;
// 界面上设置每个 RadioButton 的 Tag 或 Name 等属性来区分在 label 里显示不同内容
}
------解决方案--------------------
第一:
foreach (Control ctrl in groupBox1.Controls)
{
if (ctrl is RadioButton)
{
if (((RadioButton)ctrl).Checked )
{
//添加你需要的操作
}
}
}
第二:
在每个radiobutton里面添加事件
private void radioButton_CheckedChanged(object sender, EventArgs e)
{
RadioButton rb=(RadioButton) sender;
if (rb.Checked)
{
//添加你需要的操作
}
}
------解决方案--------------------
public void radioBtn_CheckedChange(object sender, EventArgs e)
{
if (!((RadioButton)sender).Checked)
{ return; }
string rechargeMoney = string.Empty;
switch (((RadioButton)sender).Text.ToString())
{
case "RadioButton界面显示的名字":
this.lbl_money_tip.Text = rechargeMoney;
break;
default:
break;
}
}