C # AutoSize icon adds add-on

I have an inscription on Windows.Form. I set the AutoSize property on the True shortcut, and I noticed that when I do this, it aligns the right side with ~ 5px white background. I have a Padding property set to [0, 0, 0, 0]. Is there any way to get rid of this?

I would like to get the label border as close as possible to the text inside the label.

+7
c # text winforms label
source share
2 answers

You cannot use indents and margins only. This is the default behavior.

alt text

In the above Window I set Padding and Margin to [0,0,0,0] . These 5 pixels still exist.

If you set FlatStyle = System and AutoSize = False , you can get this:

alt text

In the above Window , you no longer have these 5 pixels.

+11
source share

Good, therefore FlastStyle = System; AutoSize = false; and then set up a property that will calculate the width as follows:

 public string LabelText { set { _label.Text = value; using (Graphics g = CreateGraphics()) { _label.Width = (int)g.MeasureString(_label.Text, _label.Font).Width; } } 

}

+1
source share

All Articles