Label.AutoSize is failing to alter Width property.

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

justin creasy

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top