<原创>获取窗口上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值为空\r\n";
else
str += rList[i].Name + "的Tag值为" + rList[i].Tag.ToString();
}
}
label1.Text = str;
}

转载需声明

posted @ 2016-04-02 11:14  Magic_Cc  阅读(512)  评论(0编辑  收藏  举报