Multiline in textBox

  • Thread starter Thread starter Nicholas Paldino [.NET/C# MVP]
  • Start date Start date
N

Nicholas Paldino [.NET/C# MVP]

Alberto,

The reason it does not work is you are using @, which indicates you want
to treat the string as a literal, and not with escape characters. Remove
the @ from the beginning of the string, and it should work.

Hope this helps.
 
I want write in two different lines in a multiline textBox. I'm doing this:

txt.Text = @"Hellow\nBye";

but it doesn't work.

How can I do it? Thank you
 
Alberto said:
I want write in two different lines in a multiline textBox. I'm doing this:

txt.Text = @"Hellow\nBye";

but it doesn't work.

How can I do it? Thank you

For a start, you've got a verbatim string literal there (because of the
@), so you've literally got the text

Hellow\nBye

instead of

Hellow<line feed>Bye

which I assume you wanted. However, I think you also need to use
"\r\n" in a TextBox rather than just "\n". Whether you use "\r\n" or
Environment.NewLine is pretty much up to you - I don't believe there's
any guarantee that a TextBox on a different platform should use
Environment.NewLine to find its lines.
 
Back
Top