How do I go to a new line (in label or text box)
say
which would doCode:Public label2 As New Label()
label2.Text = "Hello\nMy name is joe."
Hello
My name is joe.
thats what I want, anyone know how?
Thanks
Printable View
How do I go to a new line (in label or text box)
say
which would doCode:Public label2 As New Label()
label2.Text = "Hello\nMy name is joe."
Hello
My name is joe.
thats what I want, anyone know how?
Thanks
vb Code:
messageBox.Show("Hello" & vbNewLine & "My name is Joe")
Don't use vbNewLine in VB.NET. Use ControlChars.NewLine or Environment.NewLine.
By the way, this:would work in C-based langauges like C# but VB doesn't support those escape sequences.Code:label2.Text = "Hello\nMy name is joe."
Thanks alot both of you
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.
A new line in HTML is <BR>Quote:
Originally Posted by Icyculyr Fr0st
ControlChars.NewLine is not the same as "\n".Quote:
Originally Posted by penagate
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.