CheckBox as Groupbox caption

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
 
T

Tim Wilson

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;
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top