Adjusting spacing between usercontrols in a FlowLayoutPanel
Asked Answered
M

1

31

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:

example flow layout panel

Melburn answered 4/7, 2012 at 14:9 Comment(0)
A
44

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.

Aleppo answered 4/7, 2012 at 14:18 Comment(4)
Thanks, 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!Melburn
Thanks for the explanation between Margin and Padding as well.Melburn
Don't forget to set the Margin also in the controls, not only in the flowLayout..Zeebrugge
A rather simple solution that helped me adjust spacing is to set a minimum size for the control: label1.MinimumSize = new Size(175, 16);Mordacious

© 2022 - 2024 — McMap. All rights reserved.