Decrease space between controls in FlowLayoutPanel

Ervin picture Ervin · Nov 1, 2012 · Viewed 8.5k times · Source

How can I decrease the space between the controls even further? I've set all the margins and padding to 0 but there is still space between my controlers.

flow layout properties

this is the space I am getting with all margins and padding set to 0. I even set the margin and padding on each controller to 0.

new spacing

and for the sake of consistency here is the code that is adding the PictureBoxes

Dim newPic As PictureBox = New PictureBox()
newPic.Image = p.Image
newPic.Size = New System.Drawing.Size(New Point(p.Size.Width * 2, 
                                                p.Size.Height * 2))
newPic.SizeMode = p.SizeMode
laytt.SetToolTip(newPic, ttstring)
AddHandler newPic.Click, AddressOf LayoutComponent_Clicked 

LayoutFlowLayout.Controls.Add(newPic)

Answer

Hans Passant picture Hans Passant · Nov 1, 2012

You are not setting the Margin property on the picture boxes you add. The default is 3,3,3,3. Add this line of code to fix the problem:

  newPic.Margin = New Padding(0)