\n\r in text box

G

Guest

Hi, I'm using \n\r to attempt to carriage return a string which will be
displayed in a text box, however, the line remains one line. How do I cariage
return a string being displayed in a text box?

e.g.
displayText = "Hello world line one\n\rHello world line two";
textbox.text = displayText;

Thanks very much in advance
Ant
 
J

Jon Skeet [C# MVP]

Ant said:
Hi, I'm using \n\r to attempt to carriage return a string which will be
displayed in a text box, however, the line remains one line. How do I cariage
return a string being displayed in a text box?

e.g.
displayText = "Hello world line one\n\rHello world line two";
textbox.text = displayText;

Use CR LF rather than LF CR:

displayText = "Hello world line one\r\nHello world line two";
 
R

Raptor

Ant said:
Hi, I'm using \n\r to attempt to carriage return a string which will be
displayed in a text box, however, the line remains one line. How do I cariage
return a string being displayed in a text box?

e.g.
displayText = "Hello world line one\n\rHello world line two";
textbox.text = displayText;

Thanks very much in advance
Ant

textbox.multiline = true;
displayText = "Hello world line one\r\nHello world line two";

your carriage return is in the wrong order

\n\r = wrong
\r\n = right
 
G

Guest

You could also use Environment.NewLine instead of \r\n. This is "safer" in
the longrun since Unix/Linux uses \n and Macintosh uses \r, your code will
run correctly on that type of box in the event of your application running
under something like Mono.
 
J

Jon Skeet [C# MVP]

Neyah said:
You could also use Environment.NewLine instead of \r\n. This is "safer" in
the longrun since Unix/Linux uses \n and Macintosh uses \r, your code will
run correctly on that type of box in the event of your application running
under something like Mono.

Well, that really depends on what Mono chooses to do with TextBoxes.
There'll be a lot of code which uses Environment.NewLine, and a lot of
code which uses \r\n. Whatever they choose to do, they'll break a lot
of code.

Environment.NewLine is just the default new line string for text files
on that system IMO (and it's not very clearly documented, so it really
is just my opinion) - it needn't dictate what a UI chooses to use.
 

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