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

1 Answer 1

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.

4
  • 3
    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!
    – wonea
    Commented Jul 4, 2012 at 14:29
  • 3
    Thanks for the explanation between Margin and Padding as well.
    – wonea
    Commented Jul 4, 2012 at 14:31
  • 2
    Don't forget to set the Margin also in the controls, not only in the flowLayout..
    – ephraim
    Commented Jun 24, 2018 at 12:41
  • 2
    A rather simple solution that helped me adjust spacing is to set a minimum size for the control: label1.MinimumSize = new Size(175, 16); Commented Sep 26, 2019 at 10:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.