Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a groupbox anchor to 3 sides of a panel, but respect its location?

Tags:

c#

winforms

I have a panel with a groupbox inside of it. I'd like the groupbox to grow and shrink as the panel is resized. However, the panel has 2 controls that will be placed above the groupbox. I want to groupbox to always stay beneath those controls.

Since I want it to resize automatically, I've turned on AutoSize. If I use dock, it of course ignores the location I've set. I can't seem to make anchors actually do anything.

How can I make the groupbox respect the location I set, but expand to fill the panel downwards and to the left and right?

like image 533
Brandon Avatar asked Dec 31 '25 09:12

Brandon


1 Answers

I don't see what's the problem, if I understand the question, the WinForms designer is perfectly capable of setting this up. Isn't this working?

this.groupBox.Anchor = AnchorStyles.Top |
                       AnchorStyles.Bottom |
                       AnchorStyles.Left |
                       AnchorStyles.Right;

enter image description here

enter image description here

enter image description here

like image 140
Fernando Espinosa Avatar answered Jan 01 '26 22:01

Fernando Espinosa