1

Using VS2012 to build a Winforms.net 4.0 app with three Label controls in a FlowLayoutPanel. Like so:

[ lastname , firstname ]

Padding and Margins on all three Label controls and the FlowLayoutPanel itself are all set to : 0.

But instead of it rendering "Smith,John"

It renders " Smith , John "

Where's the extra padding/white space coming from?

D.Forrest
  • 845
  • 1
  • 9
  • 23

1 Answers1

2

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);
Community
  • 1
  • 1
LarsTech
  • 80,625
  • 14
  • 153
  • 225