直接是获取不了Form上的控件的 应该加个容器如panal StringBuilder SB = new StringBuilder(); foreach (Control c in this.Panel1.Controls) { if (c.GetType().Name.Equals("CheckBox")) { CheckBox cb = c as CheckBox; if (cb.Checked == true) { SB.AppendLine(cb.Text); } } } this.Label1.Text = SB.ToString(); 就OK了!
foreach (Control ff in this.Controls)
{
if (ff is CheckBox)
{
CheckBox cb = ff as CheckBox;
SB.AppendLine(cb.Checked?cb.Text:"");
}
}
this.label4.Text = SB.ToString ();
label4.Refresh();
建议单步跟踪下看看有没值
StringBuilder SB = new StringBuilder();
foreach (Control c in this.Panel1.Controls)
{
if (c.GetType().Name.Equals("CheckBox"))
{
CheckBox cb = c as CheckBox;
if (cb.Checked == true)
{
SB.AppendLine(cb.Text);
}
}
}
this.Label1.Text = SB.ToString();
就OK了!
ght][/align]