Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to AutoSize the height of a Label but not the width

Tags:

c#

.net

winforms

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?

like image 212
Malfist Avatar asked Jan 12 '11 19:01

Malfist


People also ask

What will happen if the value of the autosize property of the label is true or false?

true if the control adjusts its width to closely fit its contents; otherwise, false . When added to a form using the designer, the default value is true .


1 Answers

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.

like image 59
Hans Passant Avatar answered Oct 06 '22 11:10

Hans Passant