Results 1 to 7 of 7

Thread: [2005] Going to a new line in a label (in html its \n)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Location
    Australia
    Posts
    237

    [2005] Going to a new line in a label (in html its \n)

    How do I go to a new line (in label or text box)

    say

    Code:
    Public label2 As New Label()
    
    label2.Text = "Hello\nMy name is joe."
    which would do

    Hello
    My name is joe.

    thats what I want, anyone know how?

    Thanks
    Last edited by Icyculyr Fr0st; Jun 11th, 2007 at 02:02 AM.

  2. #2
    Fanatic Member
    Join Date
    Feb 2007
    Location
    Eindhoven
    Posts
    828

    Re: [2005] Going to a new line in a label (in html its \n)

    vb Code:
    1. messageBox.Show("Hello" & vbNewLine & "My name is Joe")

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Going to a new line in a label (in html its \n)

    Don't use vbNewLine in VB.NET. Use ControlChars.NewLine or Environment.NewLine.

    By the way, this:
    Code:
    label2.Text = "Hello\nMy name is joe."
    would work in C-based langauges like C# but VB doesn't support those escape sequences.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Location
    Australia
    Posts
    237

    Re: [2005] Going to a new line in a label (in html its \n)

    Thanks alot both of you

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [2005] Going to a new line in a label (in html its \n)

    ControlChars.NewLine is exactly the same as vbNewLine or \n and none of those are platform independent. That said, .NET's not realistically platform independent either so it really doesn't matter what you use.

  6. #6
    Hyperactive Member
    Join Date
    Sep 2005
    Posts
    384

    Re: [2005] Going to a new line in a label (in html its \n)

    Quote Originally Posted by Icyculyr Fr0st
    Going to a new line in a label (in html its \n)
    A new line in HTML is <BR>

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Going to a new line in a label (in html its \n)

    Quote Originally Posted by penagate
    ControlChars.NewLine is exactly the same as vbNewLine or \n and none of those are platform independent. That said, .NET's not realistically platform independent either so it really doesn't matter what you use.
    ControlChars.NewLine is not the same as "\n".

    C-based languages support inline escape sequences that VB does not. In C-based languages "\r" is a carriage return and "\n" is a line feed. The standard Windows new line is a carriage return followed by a line feed. On most common non-Windows systems the standard line break is just a line feed.

    In VB the vbNewLine is a constant defined as a carriage return followed by a new line. ControlChars.NewLine is a constant member of the ControlChars class defined as vbNewLine. As such, both vbNewLine and ControlChars.NewLine are equivalent to "\r\n" in C-based languages. VB also supports vbCr, vbLf, ControlChars.Cr and ControlChars.Lf for the individual carriage return and line feed characters.

    Environment.NewLine is not a constant so it cannot be used where a constant value is required, unlike ControlChars.NewLine et al. Environment.NewLine will return a carriage return followed by a line feed on Windows and just a line feed on non-Windows systems.

    If you use "\n" for a new line in C# then you are actually using a non-standard value on Windows. This is not an issue in most cases but there may be some where it would matter. If you want platform independent code in VB or C# you should use Environment.NewLine for all your line breaks.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width