Word wrap for a label in Windows Forms
.net, c#, controls, label, winforms
Solution
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:
- Measure the height of the text (Graphics.MeasureString).
- If the label height is not equal to the height of the text set the height and return.
- Draw the text.
You will also need to set the ResizeRedraw style flag in the constructor.
Problem
How can one get word wrap functionality for a `Label` for text which goes out of bounds?