Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > Panels, Labels, GroupBox > Label on multiple lines

Answered Label on multiple lines

Feed from this thread
  • Bob avatar

    Posted on May 16, 2008 (permalink)

    How do I make a label span multiple lines?

    I'd like to avoid using multiple labels.

    Reply

  • Answer Martin Vasilev Martin Vasilev admin's avatar

    Posted on May 17, 2008 (permalink)

    Hello Bob,

    Thank you for writing.

    There are two ways you can do this:
    1. Using the designer: Navigate to the Text property, open its dropdown button and put the text on different lines using the Enter key.
    2. Programmatically: When you set the Text property by code, use the escape sequence "\n" for a new line:
      this.radLabel1.Text = "First line \n Second line"
    If you need additional assistance, do not hesitate to contact me again.

    Kind regards,
    Martin Vasilev
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

    Reply

  • Bob avatar

    Posted on May 19, 2008 (permalink)

    Thanks, that's the behavior I'm looking for.

    Considering usability, it would be much easier if the label supported a dragable border.  That way we could resize it while it has text, and it would resize on-the-fly...make it a lot easier than having to find the text property over and over.

    Reply

  • Angel Angel admin's avatar

    Posted on May 20, 2008 (permalink)

    Hi Bob,

    Thank you for writing.

    Just like the Microsoft Label, RadLabel cannot be sized by default. In order to apply an arbitrary size to RadLabel, set the AutoSize property to false. By default, in this mode the text is wrapped on multiple lines if the width is not enough to fit the entire text.

    If you have any additional questions, please contact me.

    Best wishes,
    Angel
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

    Reply

  • Bob avatar

    Posted on May 20, 2008 (permalink)

    I'm following your suggestion when setting the text programatically, but am not seeing the multiple lines.

    In designer mode I set the text to be:  "First Test" on the first line, and "Second Line" on the second line so that I can know it's changed.  Then when I press a button I set this:

    RadLabel_Instructions.Text = "AAA BB \n CC DD"

    And the result on screen is exactly that - all on one line. 

    Reply

  • Answer Angel Angel admin's avatar

    Posted on May 21, 2008 (permalink)

    Hi Bob,

    The given sample was for C#. If you are using Visual Basic, the code should be:

    RadLabel_Instructions.Text = "AAA BB " & Constants.vbLf & " CC DD"

    Best wishes,
    Angel
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

    Reply

  • Bob avatar

    Posted on May 21, 2008 (permalink)

    That worked, but I'm curious as to why \n wouldn't work in vb.

    Thanks!

    Reply

  • Angel Angel admin's avatar

    Posted on May 22, 2008 (permalink)

    Hello Bob,

    Putting escape characters between the quotation marks is defined by the language. The usage of '\' is specified for C# and combinations like '\n' and '\r' are also language-specific.

    Visual Basic does not allow special characters to be put inside a string.

    For differences between C# and VB, you may refer to the comparison articles below:

    http://www.harding.edu/fmccown/vbnet_csharp_comparison.html#Strings

    or

    http://www.codeproject.com/KB/dotnet/vbnet_c__difference.aspx

    I hope this helps. If you have any further questions, please contact me.

    Sincerely yours,
    Angel
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > Panels, Labels, GroupBox > Label on multiple lines
Related resources for "Label on multiple lines"

[ Features | Demos | Documentation | Knowledge Base | Telerik TV | Code Library | Step-by-step Tutorial | Blogs | Self-Paced Trainer ]