简体   繁体   English

FlowLayoutPanel控件中Winforms标签上的多余填充

[英]Unwanted Padding on Winforms Label in FlowLayoutPanel Control

Using VS2012 to build a Winforms.net 4.0 app with three Label controls in a FlowLayoutPanel. 使用VS2012构建带有FlowLayoutPanel中的三个Label控件的Winforms.net 4.0应用程序。 Like so: 像这样:

[ lastname , firstname ] [姓氏,名字]

Padding and Margins on all three Label controls and the FlowLayoutPanel itself are all set to : 0. 所有三个Label控件和FlowLayoutPanel本身的填充和边距都设置为:0。

But instead of it rendering "Smith,John" 但与其渲染“史密斯,约翰”

It renders " Smith , John " 它呈现“史密斯,约翰”

Where's the extra padding/white space coming from? 多余的填充/空白来自哪里?

The label really wants to have those extra padding spaces, so you end up fighting it. 该标签确实希望有这些额外的填充空间,所以您最终要与它抗衡。

I have had some reasonable success using this hack : 使用此技巧,我取得了一些合理的成功:

label1.AutoSize = false;
label1.FlatStyle = FlatStyle.System;
Size padSize = TextRenderer.MeasureText(".", label1.Font);
Size textSize = TextRenderer.MeasureText(label1.Text + ".", label1.Font);
label1.Size = new Size(textSize.Width - padSize.Width, textSize.Height);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM