newlines in textbox

T

tshad

I am using a TextBox as my status display and "\n" doesn't work.

What would I use to go to the next line in a TextBox.

I am doing something like:

Status.Text += String.Format("Opening
{0}\n",Path.GetFileName(strFile));

But the next line just continues on the same line.

Thanks,

Tom
 
T

Teemu

tshad said:
I am using a TextBox as my status display and "\n" doesn't work.

What would I use to go to the next line in a TextBox.

I am doing something like:

Status.Text += String.Format("Opening
{0}\n",Path.GetFileName(strFile));

But the next line just continues on the same line.

Status.Multiline=True?

-Teemu
 
T

tshad

Teemu said:
Status.Multiline=True?

That was already set.

My problem wasn't going to multiple lines. But when I did something like:

Status.Text = "line 1\n"
Status.Text = "line 2\n"

I would get:

line 1line 2.

Turns out I can use the Environment.Newline to get it to work. But I am
surprised that that the "\n" wouldn't work.

Thanks,

Tom
 
H

Herfried K. Wagner [MVP]

tshad said:
I am using a TextBox as my status display and "\n" doesn't work.

What would I use to go to the next line in a TextBox.

I am doing something like:

Status.Text += String.Format("Opening
{0}\n",Path.GetFileName(strFile));

Make sure the textbox' 'Multiline' property is set to 'true'. In addition I
suggest to use "\r\n" as line separator (which is the common line separator
on Windows), or 'Environment.NewLine' if you are targeting different
operating systems using different line separator character sequences.
 
J

Jack Jackson

I am using a TextBox as my status display and "\n" doesn't work.

What would I use to go to the next line in a TextBox.

I am doing something like:

Status.Text += String.Format("Opening
{0}\n",Path.GetFileName(strFile));

But the next line just continues on the same line.

Thanks,

Tom

I believe you can use \r\n for cr/lf. You can also use
Environment.Newline:

Status.Text += String.Format("Opening {0}{1}", _
Path.GetFileName(strFile), _
Environment.NewLine)
 

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