D.Forrest
D.Forrest

Reputation: 845

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. 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?

Upvotes: 1

Views: 772

Answers (1)

LarsTech
LarsTech

Reputation: 81610

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);

Upvotes: 2

Related Questions