WinForm小知识点总结
1:CheckBox(全选,反选)容器内或指定容器内
View Code
foreach (Control ctl in this.Controls) //this.groupBox1.Controls { if (ctl is CheckBox) { CheckBox ck = ctl as CheckBox; if (ck!=null) { ck.Checked = true; // ck.Checked = !ck.Checked; } } }
2:清空某容器内的控件的内容
View Code
foreach (Control ctl in this.groupBox2.Controls) { if (ctl is CheckBox) { CheckBox ck = ctl as CheckBox; if (ck != null) { ck.Checked = false; } } if (ctl is TextBox) { TextBox tb = ctl as TextBox; tb.Text = String.Empty; } if (ctl is RichTextBox) { RichTextBox rtb = ctl as RichTextBox; rtb.Text = String.Empty; } }