By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,529 Members | 1,860 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,529 IT Pros & Developers. It's quick & easy.

Line break in a windows application

P: n/a
Hello, All!

I have created an application with a multiline textbox on the form.
When I press a button, it has to show something and then break
the line and show something else.
I tried "\n", ((char)13) and ((char)10) - they don't work.
When I enter a break by hand (just press enter) and run through
each character in that string, the line break character has code
13 10 (yes, 2 numbers for some reason)
The possible reason is that 'Enter' is a "control" key (a char with
ASCII code less than 32) - they usually return 2 numbers...

What should I do to break line in the textbox?
Alternative way was to use TextWriter:
string LineBreak=(new System.IO.StringWriter()).NewLine;

but there must be another way of doing it...
and then just use that string:
this.TextBox1.AppendText("Hello"+LineBreak+"World" );

That is kind of stupid...

With best regards, Nurchi BECHED.
Nov 16 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
What happens when you do this?:

this.TextBox1.AppendText("Hello"+Environment.NewLi ne+"World");
"Nurchi BECHED" wrote:
Hello, All!

I have created an application with a multiline textbox on the form.
When I press a button, it has to show something and then break
the line and show something else.
I tried "\n", ((char)13) and ((char)10) - they don't work.
When I enter a break by hand (just press enter) and run through
each character in that string, the line break character has code
13 10 (yes, 2 numbers for some reason)
The possible reason is that 'Enter' is a "control" key (a char with
ASCII code less than 32) - they usually return 2 numbers...

What should I do to break line in the textbox?
Alternative way was to use TextWriter:
string LineBreak=(new System.IO.StringWriter()).NewLine;

but there must be another way of doing it...
and then just use that string:
this.TextBox1.AppendText("Hello"+LineBreak+"World" );

That is kind of stupid...

With best regards, Nurchi BECHED.

Nov 16 '05 #2

P: n/a
Hi

Try this:

Dim sData As New StringBuilder()

sData.AppendFormat("This is line one {0}", ControlChars.CrLf)
sData.AppendFormat("This is line Two{0}", ControlChars.CrLf)
sData.AppendFormat("This is line Three{0}", ControlChars.CrLf)

Not sure about the CrLf on the ControlChars class, don't have my IDE loaded,
but if you type . you'll see a list of properties you can use.

txtOut.Text = sData.ToString()

You'll have to set the multiline property of the Textbox to true. Hope this
helps.

Cheers

Raj
"Nurchi BECHED" <nu****@telus.net> wrote in message
news:hq9Tc.17630$fz2.15309@edtnps89...
Hello, All!

I have created an application with a multiline textbox on the form.
When I press a button, it has to show something and then break
the line and show something else.
I tried "\n", ((char)13) and ((char)10) - they don't work.
When I enter a break by hand (just press enter) and run through
each character in that string, the line break character has code
13 10 (yes, 2 numbers for some reason)
The possible reason is that 'Enter' is a "control" key (a char with
ASCII code less than 32) - they usually return 2 numbers...

What should I do to break line in the textbox?
Alternative way was to use TextWriter:
string LineBreak=(new System.IO.StringWriter()).NewLine;

but there must be another way of doing it...
and then just use that string:
this.TextBox1.AppendText("Hello"+LineBreak+"World" );

That is kind of stupid...

With best regards, Nurchi BECHED.

Nov 16 '05 #3

P: n/a
Hello, Richard!
You wrote on Fri, 13 Aug 2004 13:55:01 -0700:

Thanks for suggestion. It still didn't work.
Something just came up to my mind:
somewhere in the program I converted received data into 'ASCII',
but even when I changed it back to 'Default,' it didn't help...

Thanks

R> this.TextBox1.AppendText("Hello"+Environment.NewLi ne+"World");

R> "Nurchi BECHED" wrote:

??>> Hello, All!
??>>
??>> I have created an application with a multiline textbox on the form.
??>> When I press a button, it has to show something and then break
??>> the line and show something else.
??>> I tried "\n", ((char)13) and ((char)10) - they don't work.
??>> When I enter a break by hand (just press enter) and run through
??>> each character in that string, the line break character has code
??>> 13 10 (yes, 2 numbers for some reason)
??>> The possible reason is that 'Enter' is a "control" key (a char with
??>> ASCII code less than 32) - they usually return 2 numbers...
??>>
??>> What should I do to break line in the textbox?
??>> Alternative way was to use TextWriter:
??>> string LineBreak=(new System.IO.StringWriter()).NewLine;
??>>
??>> but there must be another way of doing it...
??>> and then just use that string:
??>> this.TextBox1.AppendText("Hello"+LineBreak+"World" );
??>>
??>> That is kind of stupid...
??>>
??>> With best regards, Nurchi BECHED.
??>>

With best regards, Nurchi BECHED.
Nov 16 '05 #4

P: n/a
Nurchi BECHED <nu****@telus.net> wrote:
I have created an application with a multiline textbox on the form.
When I press a button, it has to show something and then break
the line and show something else.
I tried "\n", ((char)13) and ((char)10) - they don't work.
When I enter a break by hand (just press enter) and run through
each character in that string, the line break character has code
13 10 (yes, 2 numbers for some reason)
The possible reason is that 'Enter' is a "control" key (a char with
ASCII code less than 32) - they usually return 2 numbers...

What should I do to break line in the textbox?


Use "\r\n", otherwise known as carriage-return line-feed.

The correct line terminator for whatever platform you're on is given by
Environment.NewLine, but as TextBox is somewhat Windows-specific
anyway, you can just use "\r\n".

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5

P: n/a
Hello, Jon!
You wrote on Sat, 14 Aug 2004 10:23:22 +0100:

JSC> Nurchi BECHED <nu****@telus.net> wrote:
??>> I have created an application with a multiline textbox on the form.
??>> When I press a button, it has to show something and then break
??>> the line and show something else.
??>> I tried "\n", ((char)13) and ((char)10) - they don't work.
??>> When I enter a break by hand (just press enter) and run through
??>> each character in that string, the line break character has code
??>> 13 10 (yes, 2 numbers for some reason)
??>> The possible reason is that 'Enter' is a "control" key (a char with
??>> ASCII code less than 32) - they usually return 2 numbers...
??>>
??>> What should I do to break line in the textbox?

JSC> Use "\r\n", otherwise known as carriage-return line-feed.

JSC> The correct line terminator for whatever platform you're on is given
JSC> by Environment.NewLine, but as TextBox is somewhat Windows-specific
JSC> anyway, you can just use "\r\n".

It doesn't work, and I have already said that Environment.NewLine didn't
help
either.
I guess if I give more background on the program, you might get some more
ideas...
The program I made consists of 2 applications: Client and Server.
It is some kind of messenger (rather something closer to NetMeeting)
2 programs just connect with each other on the network by IP address using
specified
port and then exchange text messages...

On the serverside I even tried something like this:
(tried this.tbMessageIn.AppendText() as well)

this.tbMessageIn.Text+=
this.server.Message+" |sdfsdfsdf| ";

The method that takes care of receiving messages is a tick of a timer object
with
interval 100ms, but I don't think this could be a problem...

'server' is an instance of 'TCP_Server' class which I wrote.
'Message' is a new property in the class which is defined as follows:
public string Message
{
get
{
return this.Received;
}
set
{
this.Sent=value;
}
}
//Received and Sent are private string variables for TCP_Server class

It only adds 'this.server.Message' but not the remaining ' |sdfsdfsdf| '
If I hit 'Enter' in the outgoing message before clicking 'Send', it goes
there as part of the message...
I mean
The
Text
Like
This

Would be transferred as 4 lines, so it doesn't remove '\n' characters
from the string, it for some reason just doesn't let me add anything
to a textbox locally...

With best regards, Nurchi BECHED.
Nov 16 '05 #6

P: n/a
Just wanted to point something out:
If I "add" end of line character to outgoing message, then it works just
fine,
but why it can't add the same thing locally after receiving the data

this.server.SendMessage(this.tbMessageOut.Text+"\r \n")

With best regards, Nurchi BECHED.
Nov 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.