放到GroupBox控件里无论是否选中都只能输出“您选择的权限如下”。拖出来却能运行。
private void button1_Click(object sender, EventArgs e)
{
string strpop = "您选择的权限如下";
foreach(Control ctrl in this.Controls)
{
if(ctrl.GetType().Name=="CheckBox")
{
CheckBox cBox=(CheckBox)ctrl;
if(cBox.Checked==true)
{
strpop+="\n"+cBox.Text;
}
else
{
strpop = "无";
}
}
}
MessageBox.Show(strpop);
}
private void button2_Click(object sender, EventArgs e)
{
foreach (Control ctrl in this.Controls)
{
if (ctrl.GetType().Name == "CheckBox")
{
CheckBox cBox = (CheckBox)ctrl;
cBox.Checked = true;
}
}
}
private void button3_Click(object sender, EventArgs e)
{
foreach (Control ctrl in this.Controls)
{
if (ctrl.GetType().Name == "CheckBox")
{
CheckBox cBox = (CheckBox)ctrl;
cBox.Checked = false;
}
}
}