Decrease space between controls in FlowLayoutPanel
Asked Answered
A

2

10

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)
Asir answered 1/11, 2012 at 18:51 Comment(4)
Is it not enough for you if you set all margins of each contained control to 0?Prouty
I just tried that and it did decrease the space but there is still a space (2 pixels?) between themAsir
new image added showing spacingAsir
I still have a hard time guessing which controls you are using, and what is the end goal of yours, but see my answer - hope it clears things up.Prouty
Z
15

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)
Zaller answered 1/11, 2012 at 19:40 Comment(0)
P
4

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.

Prouty answered 1/11, 2012 at 19:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.