Adjusting spacing between usercontrols in a FlowLayoutPanel

34,721

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.

Share:
34,721

Related videos on Youtube

wonea
Author by

wonea

Love developing C# software, especially web services, system/desktop applications and Xamarin.

Updated on February 03, 2020

Comments

  • wonea
    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:

    example flow layout panel

  • wonea
    wonea almost 12 years
    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
    wonea almost 12 years
    Thanks for the explanation between Margin and Padding as well.
  • ephraim
    ephraim about 6 years
    Don't forget to set the Margin also in the controls, not only in the flowLayout..
  • MrJack Mcfreder
    MrJack Mcfreder over 4 years
    A rather simple solution that helped me adjust spacing is to set a minimum size for the control: label1.MinimumSize = new Size(175, 16);