NewLine in a textbox

  • Thread starter Thread starter JC
  • Start date Start date
J

JC

I can't get \n to work in a multiline textbox, what do I need to do? If I
need to add a hard return then what is that sequence.

jc
 
JC said:
I can't get \n to work in a multiline textbox, what do I need to do? If I
need to add a hard return then what is that sequence.

Use \r\n instead of \n
 
JC said:
I can't get \n to work in a multiline textbox, what do I need to do? If I
need to add a hard return then what is that sequence.

'\n' is line-feed.

I presume you're running this app on Windows, in which case a newline is
is: "\r\n".

Environment.NewLine will return the newline specifier for whichever
platform your app is running on.

So:

textBox.AppendText("foo" + Environment.NetLine + "bar");
 
C# Learner said:
Environment.NewLine will return the newline specifier for whichever
platform your app is running on.

So:

textBox.AppendText("foo" + Environment.NetLine + "bar");

Note, however, that "the newline specifier for the platform" won't
*necessarily* be the newline specifier required to get a text box to
use new lines. It's more (IMO) for the default newline in text files.
 
Jon said:
Note, however, that "the newline specifier for the platform" won't
*necessarily* be the newline specifier required to get a text box to
use new lines.

Would you recommend using "\r\n" instead, then, for effecting a new line
in a ".NET" text box?

I've been using Environment.NewLine as I'd expect, for example, that
Mono text boxes use *nix new line specifiers. Does anyone know if this
is the case?
 
C# Learner said:
Would you recommend using "\r\n" instead, then, for effecting a new line
in a ".NET" text box?

I'm not sure what the best approach is, to be honest. I think for the
moment I'd use \r\n when using System.Windows.Forms.TextBox - but that
doesn't mean I'm right to!
I've been using Environment.NewLine as I'd expect, for example, that
Mono text boxes use *nix new line specifiers. Does anyone know if this
is the case?

I suspect it may well depend on what kind of textbox you're using. If
you're using the WINE, S.W.F.TextBox could well still need \r\n, but
the GTK# bindings may use \n. It's a bit of a mess, really :(
 
Jon said:
I suspect it may well depend on what kind of textbox you're using. If
you're using the WINE, S.W.F.TextBox could well still need \r\n, but
the GTK# bindings may use \n. It's a bit of a mess, really :(

Sounds it. I might give Mono a when I get time (which I've been meaning
to do anyway) and test out different GUI frameworks.
 
Jon said:
Note, however, that "the newline specifier for the platform" won't
*necessarily* be the newline specifier required to get a text box to
use new lines. It's more (IMO) for the default newline in text files.

By the way, thanks for pointing this out.
 

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

Back
Top