Ironically, turning off AutoSize
by setting it to false
allowed me to get the label control dimensions to size it both vertically and horizontally which effectively allows word-wrapping to occur.
If you want some dynamic sizing in conjunction with a word-wrapping label you can do the following:
Handle the ClientSizeChanged event
for the panel, making the
label fill the space:
private void Panel2_ClientSizeChanged(object sender, EventArgs e)
{
label1.MaximumSize = new Size((sender as Control).ClientSize.Width - label1.Left, 10000);
}
Set Auto-Size
for the label to true
Dock
for the label to Fill
You can use a TextBox
and set multiline
to true
and canEdit
to false
.
Just set Label AutoSize property to False. Then the text will be wrapped and you can re-size the control manually to show the text.
If you open the dropdown for the Text
property in Visual Studio, you can use the enter key to split lines. This will obviously only work for static text unless you know the maximum dimensions of dynamic text.
Change your maximum size,
label1.MaximumSize = new Size(100, 0);
And set your autosize to true.
label1.AutoSize = true;
That's it!
Source: Stackoverflow.com