<原创>获取窗口上RadioButton的Tag值

private void button2_Click(object sender, EventArgs e)
{
CheckRadioButton();
}
List<RadioButton> rList = new List<RadioButton>();
private void CheckRadioButton()
{
string str = "";
foreach (Control rButton in this.Controls)
{
if (this.Controls.Count == 0)
{
label1.Text = "当前窗体没有控件";
return;
}
if (rButton is RadioButton)
rList.Add((RadioButton)rButton);
}
if (rList.Count == 0)
str = "当前窗体没有RadioButton控件";
else
{
for (int i = 0; i < rList.Count; i++)
{
if (rList[i].Tag == null)
str += rList[i].Name + "的Tag值为空 ";
else
str += rList[i].Name + "的Tag值为" + rList[i].Tag.ToString();
}
}
label1.Text = str;
}

转载需声明

人最宝贵的就是生命,生命对于每个人来说只有一次。人的一生应该这样度过:回首往事,他不会因为虚度年华而悔恨,也不会因为碌碌无为而羞愧;临终之际,他能够说:“我的整个生命和全部精力,都献给了世界上最壮丽的事业——为解放全人类而斗争。”
原文地址:https://www.cnblogs.com/Imgiser/p/5347134.html