Label on multiple lines

8 posts, 2 answers
  1. Bob
    Bob avatar
    72 posts
    Member since:
    May 2008

    Posted 16 May 2008 Link to this post

    How do I make a label span multiple lines?

    I'd like to avoid using multiple labels.
  2. Answer
    Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 17 May 2008 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Bob
    Bob avatar
    72 posts
    Member since:
    May 2008

    Posted 19 May 2008 Link to this post

    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.
  5. Angel
    Admin
    Angel avatar
    121 posts

    Posted 20 May 2008 Link to this post

    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
  6. Bob
    Bob avatar
    72 posts
    Member since:
    May 2008

    Posted 20 May 2008 Link to this post

    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. 

  7. Answer
    Angel
    Admin
    Angel avatar
    121 posts

    Posted 21 May 2008 Link to this post

    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
  8. Bob
    Bob avatar
    72 posts
    Member since:
    May 2008

    Posted 21 May 2008 Link to this post

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

    Thanks!
  9. Angel
    Admin
    Angel avatar
    121 posts

    Posted 22 May 2008 Link to this post

    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
Back to Top
UI for WinForms is Visual Studio 2017 Ready