CheckBox as Groupbox caption

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hello,

how do i create a groupbox which has a checkbox instead of a label as
caption. with that checkbox i want to enable/disable the controls inside the
groupbox

thanks
 
Just set the Text of the GroupBox to an empty string, add a CheckBox, place
it at the top of the GroupBox, hook into the CheckedChanged event for the
CheckBox, and inside this event handler you can traverse the Controls
collection for the GroupBox and set the Enabled property of each control to
the proper state based on the CheckBox Checked property. You'll need to go
through each control so that you can purposely skip the CheckBox. The other
option is to place all the controls, except the CheckBox, onto a Panel and
then just enable/disable the Panel.

private void checkBox1_CheckedChanged(object sender, System.EventArgs e)
{
foreach (Control ctrl in this.groupBox1.Controls)
{
if (ctrl != this.checkBox1)
{
ctrl.Enabled = this.checkBox1.Checked;
}
}
}
 
Back
Top