Community discussion forum

Wrap text in a label control

This is a comment thread discussing Wrap text in a label control
  • 10 years ago

    This thread is for discussions of Wrap text in a label control.

  • 7 years ago
    It appears that you're limiting every wrapped label's width to 2700..? Why not pass the desired with for the label as a paramater or use the current label's width?   And, with that in mind, MS's label control has a WordWrap property which does wrap the text to the label's width.
  • 1 year ago

    Here's my C# version 

    <code> 

    private string GetWrappedText(string Text, int LineLength)
    {

    Text = Text.Replace("\r\n", "");
    int len = Text.Length;
    int startPos = 0;
    StringBuilder sb = new StringBuilder();
    while (((len - startPos) / LineLength) >= 1)
    {

    int endpoint = Text.Substring(startPos, LineLength).LastIndexOfAny(new char[] { ',', ' ', ':' });
    sb.AppendLine(Text.Substring(startPos, endpoint));
    startPos += endpoint + 1;

    }

    sb.Append(Text.Substring(startPos));
    return sb.ToString();

    }

     

    </code>

Post a reply

Enter your message below

Sign in or Join us (it's free).

We'd love to hear what you think! Submit ideas or give us feedback