Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Margin be enforced even with Dock property set?

I have a WinForms Form with a few controls on it. All of them are GrouBox 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?

like image 718
Kornelije Petak Avatar asked Aug 14 '11 15:08

Kornelije Petak


People also ask

What is use of dock property?

Use the Dock property to define how a control is automatically resized as its parent control is resized. For example, setting Dock to DockStyle. Left causes the control to align itself with the left edges of its parent control and to resize as the parent control is resized.

Which Layout control can set the property of control at runtime?

The TableLayoutPanel control arranges its contents in a grid. Because the layout is done both at design time and run time, it can change dynamically as the application environment changes.

Which setting of the dock property causes the control to fill its form or container control?

The docking mode can be any side of the control's container, or set to fill the remaining space of the container.


2 Answers

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

like image 104
sunnyaprilafternoon Avatar answered Sep 27 '22 01:09

sunnyaprilafternoon


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.

like image 28
LarsTech Avatar answered Sep 23 '22 01:09

LarsTech