Label.AutoSize is failing to alter Width property.

  • Thread starter Thread starter patrick.lioi
  • Start date Start date
P

patrick.lioi

Label label = new Label();
label.Width = 1;
label.AutoSize = true;
label.Text = "A long string, requiring a width larger than 1.";
//At this point, Width is still 1.

What am I missing? Shouldn't AutoSize adjust the "Size"
"Auto"matically to fit the string?
 
Patrick:

I'm not sure if this is different with various versions of .NET, if it
is I am using VS 2005 with .NET 2.0.

That said, the problem is the width and height of your controls will
not be processed until the controls is added to the form. If you need
the width to be calculated before you make the control visible, try
setting it's visibility to false, add it to your form, get the
calculated width, then make your control visible when you are ready.

Hope this helps, good luck!
 
Back
Top