vb.net 减少 FlowLayoutPanel 中控件之间的空间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13183616/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Decrease space between controls in FlowLayoutPanel
提问by Ervin
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.
如何进一步减少控件之间的空间?我已将所有边距和填充设置为 0,但我的控制器之间仍有空间。


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.
这是我得到的空间,所有边距和填充设置为 0。我什至将每个控制器上的边距和填充设置为 0。


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)
回答by Hans Passant
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:
您没有在添加的图片框上设置 Margin 属性。默认值为 3,3,3,3。添加这行代码来解决问题:
newPic.Margin = New Padding(0)
回答by Neolisk
Every control handles margins differently, even with standard controls. Have a look at this example:
每个控件处理边距的方式不同,即使使用标准控件也是如此。看看这个例子:


Notice that a Buttonreserves 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 Buttonsalso have a border, but it's harder to justify visually, even when zoomed in.
请注意, aButton在它周围保留了一些空间,而 TextBox 占据了一切。您可能会问为什么它们之间有 2 个像素,您可以清楚地看到。为此 - 请复制/粘贴到 Paint 并放大。这 2 个像素实际上是边框,这就是绘制控件的方式。我肯定Buttons也有边框,但即使放大也很难在视觉上证明其合理性。
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.
如果你想改变它,你需要创建一个自定义控件并覆盖它的绘制方式,即手动剪切边框或类似的。但我不建议这样做,以保持 UI 一致。

