0

I have MSVC 2010 and I need to put a groupbox inside a groupbox. It does not work when I tried to use GUI editor, and it does not work when I use:

groupbox1.Controls.Add(groupbox2);
groupbox.Visible = true;

If I use the code above the second box just does not display. If I use the GUI editor the second box just does not show inside the first one.

Can anybody help please?

2
  • Perhaps groupbox.Visible = true; should be groupbox2.Visible = true;? Aug 2, 2012 at 5:57
  • 1
    Works just fine for me when I try to create a GroupBox inside of another GroupBox at design time. What's going wrong for you? Select GroupBox in the Toolbox, drag to create one on your form, then copy that original GroupBox, paste another instance on your form, and drag it inside of the original GroupBox. Boom, nested groupboxes. Aug 2, 2012 at 6:38

3 Answers 3

1

Change child control location:

groupBox1.Controls.Add(groupBox2);
groupBox2.Location = new Point(10, 10);

from Control.Location (MSDN):

Gets or sets the coordinates of the upper-left corner of the control relative to the upper-left corner of its container.

0
0

did you add the groupBox1 into the main Control?

this.Controls.Add(groupBox1);

Also try setting Visible = true on groupBox 2 as well

0

I think you just need to add a groupbox.Location. Then it will appear.

var groupBox = new GroupBox();
groupBox1.Controls.Add(groupBox);
groupBox.Location = new Point(somex,somey);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.