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?
In my case (label on a panel) I set
label.AutoSize = false
andlabel.Dock = Fill
. And the label text is wrapped automatically.If you really want to set the label width independent of the content, I find that the easiest way is this:
Now the label is of constant width, but it adapts its height automatically.
Then for dynamic text, decrease the font size. If necessary, use this snippet in the sub where the label text is set:
This helped me in my Form called InpitWindow: In Designer for Label:
Whole code of my form
Handle the
ClientSizeChanged event
for the panel, making the label fill the space:Set
Auto-Size
for the label totrue
Dock
for the label toFill