Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decrease space between controls in FlowLayoutPanel

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)
like image 810
Ervin Avatar asked Nov 01 '12 18:11

Ervin


2 Answers

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)
like image 145
Hans Passant Avatar answered Sep 30 '22 06:09

Hans Passant


Every control handles margins differently, even with standard controls. Have a look at this example:

enter image description here

Notice that a Button reserves some space around it, while a TextBox takes everything. You may ask why 2 pixels in between them which you can clearly see. For that - please copy/paste into Paint and zoom in. Those 2 pixels are in fact the border, this is how a control is drawn. I am sure Buttons also have a border, but it's harder to justify visually, even when zoomed in.

If you want to change that, you would need to create a custom control and override how it's drawn, i.e. manually cut borders from it or similar. But I would not recommend doing it, to keep UI consistent.

like image 30
Neolisk Avatar answered Sep 30 '22 07:09

Neolisk