C# – How to AutoSize the height of a Label but not the width

cnetwinforms

I have a Panel that I'm creating programmatically; additionally I'm adding several components to it.

One of these components is a Label which will contain user-generated content.

I don't know how tall the label should be, but it does have a fixed width.

How can I set the height so that it displays all the text, without changing the width?

Best Answer

Just use the AutoSize property, set it back to True.

Set the MaximumSize property to, say, (60, 0) so it can't grow horizontally, only vertically.