How can we get word wrap functionality for a label in Windows Forms?
I placed a label in a panel and added some text to label dynamically. But it exceeds the panel length. How can I solve this?
How can we get word wrap functionality for a label in Windows Forms?
I placed a label in a panel and added some text to label dynamically. But it exceeds the panel length. How can I solve this?
Use
style="overflow:Scroll"
in the label as in the below HTML. This will add the scroll bar in the label within the panel.The simple answer for this problem is to change the DOCK property of the Label. It is "NONE" by default.
From MSDN, Automatically Wrap Text in Label:
I had to find a quick solution, so I just used a TextBox with those properties:
Set the AutoEllipsis Property to 'TRUE' and AutoSize Property to 'FALSE'.
The quick answer: switch off AutoSize.
The big problem here is that the label will not change its height automatically (only width). To get this right you will need to subclass the label and include vertical resize logic.
Basically what you need to do in OnPaint is:
You will also need to set the ResizeRedraw style flag in the constructor.