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?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Igor
  • 5,620
  • 11
  • 51
  • 103
  • Perhaps `groupbox.Visible = true;` should be `groupbox2.Visible = true;`? – Andre Calil Aug 02 '12 at 05: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](http://i.stack.imgur.com/JCUBC.png). – Cody Gray - on strike Aug 02 '12 at 06:38

3 Answers3

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.

Ria
  • 10,237
  • 3
  • 33
  • 60
0

did you add the groupBox1 into the main Control?

this.Controls.Add(groupBox1);

Also try setting Visible = true on groupBox 2 as well

Vinoth
  • 2,419
  • 2
  • 19
  • 34
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);
Jonas W
  • 3,200
  • 1
  • 31
  • 44