473,473 Members | 1,800 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Line break in a windows application

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
6 16227
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: CLEAR-RCIC | last post by:
I want to write a windows app that accepts command line arguments. Does anyone know if this can be done and if so, how to do it.
5
by: calmar | last post by:
Hi all, unfotunately, 'commands.getstatusoutput(command)' does not work under windows. Would there be any alternative? os.system also just provides the exit number I think. thanks a lot,
4
by: News | last post by:
Hi Everyone, The attached code creates client connections to websphere queue managers and then processes an inquiry against them. The program functions when it gets options from the command...
9
by: Adi | last post by:
Hello eveyone, I wanna ask a very simple question here (as it was quite disturbing me for a long time.) My problem is to read a file line by line. I've tried following implementations but still...
10
by: Itaichuk | last post by:
Hi I read in several CSS tutorials that block-level elements, such as <div& <pare rendered with an implicit line break before and after. I set to test this out using the following HTML: I...
10
by: somenath | last post by:
Hi All, I was trying to write a function which will read one line from a specified file and return the line. It is currently working fine. But it would be very much helpful for me if some one...
7
by: Jwe | last post by:
Hi, I've written a program which has both a command line interface and Windows form interface, however it isn't quite working correctly. When run from command line with no arguments it should...
2
by: Brad Pears | last post by:
I have a vb.net 2005 project and wonder what else needs to be enabled to allow me to edit a line(s) of code while in break mode and then bne able to carry on with execution of the application. ...
3
by: sreemathy2000 | last post by:
I need to display a message box in my windows application.. the text for the message is read from app.config. i need to put a line break in the message box. i tried to put \n in the text that...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.