'How to set a gap between 2 panels in c# winform, details below

I place a panel with dock type left and place 2 panels with dock type top in the parent panel. But I want to place a gap between these 2 panels because the margin is not working on that panels. How to do that in C# winform? Please help...



Solution 1:[1]

I don't think you can when docking. What you could do is dock one Panel as container and then put another Panel inside that, leaving a margin as required and then anchoring to all four sides. The inner Panel is then used for your other controls rather than the outer.

Alternatively, you could use Anchor instead of Dock, which would allow you to explicitly position each Panel. The correct combination of anchored edges would simulate docking, i.e. top, left and bottom for the left Panel and top, left and right for the top Panels.

I guess the other alternative would be to introduce additional Panels to act specifically as separators between those you intend to use as containers.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1