42

I have a WinForms Form with a few controls on it. All of them are GroupBox controls and I want them stacked, with a vertical margin set between them. I have set the Dock property to Top and it stacks them alright, but ignores the margin (controls are as close to each other as they can be).

Can these margins still somehow be enforced? Basically, it would calculate the regular docked position (as if the margin was 0) then apply the margin. Is something like this possible?

The other way I've tried this is with FlowLayoutPanel with TopDown option. However, then I need to manually set the size and Left/Right anchors.

Is there any easy way to acomplish this scenario or should I stick with what I already have?

Eric
  • 19,525
  • 19
  • 84
  • 147
Kornelije Petak
  • 9,412
  • 15
  • 68
  • 96

3 Answers3

37

Place each GroupBox in a Panel, Set Panel Dock Property to Top, Group Box Dock Property to Fill. Then set Padding on the panels.

18

The set docking property will ignore your padding properties between GroupBox controls, so yes, your best bet is the Flow or Table panels to do this.

LarsTech
  • 80,625
  • 14
  • 153
  • 225
8

Add a dummy transparent panel docked between each textbox with a height equal to the exact distance you require.

Haz
  • 203
  • 6
  • 15