easy one // textBox.text and return/new line character....

G

genc ymeri

Hi ,
I have this simple code :

string hopeTextShowsInTwoLines = "lineOne \n line two";
textBox1.Text = hopeTextShowsInTwoLines;

but text shows in one line. What should I do for thenew lines "\n"
characters to send the rest of the text in the new line of the textBox ?

THank You
 
M

Morten Wennevik

Hi genc ymeri,

First, you should use \r\n and not just \n, as you aren't always
guaranteed that just \n will work.

In your case you need to set the TextBox's MultiLine property to true.
 
P

Paul E Collins

Morten Wennevik said:
First, you should use \r\n and not just \n

"\r\n" can be used if you only intend your application to run under
Windows.

If you're concerned about portability, use Environment.NewLine.

P.
 
G

genc ymeri

thnx :)

Paul E Collins said:
"\r\n" can be used if you only intend your application to run under
Windows.

If you're concerned about portability, use Environment.NewLine.

P.
 
J

Jon Skeet [C# MVP]

Paul E Collins said:
"\r\n" can be used if you only intend your application to run under
Windows.

If you're concerned about portability, use Environment.NewLine.

I don't know about that - Environment.NewLine is to do with the new
line for the platform in general. There's no guarantee it'll be what
the *text box* uses for a new line. For instance, running with Mono
under Linux, I'd expect Environment.NewLine to be '\n' but if they're
trying to get Windows Forms compatibility with .NET, TextBox may well
still require '\r\n'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top