Adjusting spacing between usercontrols in a FlowLayoutPanel
Panel
and other similar controls have both Margin
and Padding
properties. Padding determines spacing internal to the control ...such as a panel. If Padding is set to 3 (All) in a Panel control, then controls will snap to 3 pixels of padding against internal edges of the control.
Margin works the same way, but between other controls. If Margin is set to 3 (All), controls will automatically snap to the margin spacing.
I haven't used the FlowLayoutPanel but once and, IIRC, you can set padding for the cells. Check your margin on your user control, and check the padding for the layout cells. Set one to 0 and the other to 3.
Related videos on Youtube
![wonea](https://i.stack.imgur.com/x93aw.jpg?s=256&g=1)
wonea
Love developing C# software, especially web services, system/desktop applications and Xamarin.
Updated on February 03, 2020Comments
-
wonea over 4 years
I'm building a WinForms application Window (form), inside that I'm using a FlowLayoutPanel, with usercontrols added to this. Now I've been looking through the properties of both the FlowLayoutPanel and UserControl but can't seem to find anything to do with the spacing between usercontrols. I want the usercontrols to be closer to each other, if only by a couple of pixels. The usercontrols themselves have no space either side of the numericUpDown. Any suggestions would be helpful.
My FlowLayoutPanel:
-
wonea almost 12 yearsThanks, you are right. The margin on the usercontrol was set to 3,3,3,3 - (All, Left, Top, Right, Bottom). A quick adjustment and things look decidedly less spacey!
-
wonea almost 12 yearsThanks for the explanation between Margin and Padding as well.
-
ephraim about 6 yearsDon't forget to set the Margin also in the controls, not only in the flowLayout..
-
MrJack Mcfreder over 4 yearsA rather simple solution that helped me adjust spacing is to set a minimum size for the control:
label1.MinimumSize = new Size(175, 16);