473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Newline in Textbox

Hi, I am a learner for C# and .Net.

I want to know how to put a line break to a string so that when it show in
the textbox the text will be displayed in saperated lines.

e.g.:

String s;
s = "AAAAAAAAAAAAAAAAAAAAA";
s += "BBBBBBBBBBBBBBBBBBBBBBB";
txtOutput.Text = s;

I want to show them like:
AAAAAAAAAAAAAAAAAAAAA
BBBBBBBBBBBBBBBBBBBBBBB

But the output is always in one line:
AAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBB

Even I include a "\n" at the end at the first line:
s = "AAAAAAAAAAAAAAAAAAAAA\n";

Thanks
Nov 16 '05 #1
5 12097
hi,kaka

First make sure the attribute "TextMode" of the textbox have set

to "MultiLine" . Then u can out put the text displayed in saperated lines by

this 2 ways:

1. String s;
s = @"AAAAAAAAAAAAAAAAAAAAA
BBBBBBBBBBBBBBBBBBBBBBB";
txtOutput.Text = s;

2. String s;
s = "AAAAAAAAAAAAAAAAAAAAA";
s += "\nBBBBBBBBBBBBBBBBBBBBBBB";
txtOutput.Text = s;
Hope that is what you were looking for.

---
Chison Choi
msn:ch****@msn.com
--
"Kaka" <ka**@hotmail.com> дÈëÓʼþ
news:uM**************@TK2MSFTNGP09.phx.gbl...
Hi, I am a learner for C# and .Net.

I want to know how to put a line break to a string so that when it show in
the textbox the text will be displayed in saperated lines.

e.g.:

String s;
s = "AAAAAAAAAAAAAAAAAAAAA";
s += "BBBBBBBBBBBBBBBBBBBBBBB";
txtOutput.Text = s;

I want to show them like:
AAAAAAAAAAAAAAAAAAAAA
BBBBBBBBBBBBBBBBBBBBBBB

But the output is always in one line:
AAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBB

Even I include a "\n" at the end at the first line:
s = "AAAAAAAAAAAAAAAAAAAAA\n";

Thanks

Nov 16 '05 #2
Hi Kaka,

try this

s = "AAAAAAAAAAAAAAAAAAAAA" + Environment.NewLine;
s += "BBBBBBBBBBBBBBBBBBBBBBB";

"Kaka" <ka**@hotmail.com> schrieb im Newsbeitrag
news:uM**************@TK2MSFTNGP09.phx.gbl... Hi, I am a learner for C# and .Net.

I want to know how to put a line break to a string so that when it show in
the textbox the text will be displayed in saperated lines.

e.g.:

String s;
s = "AAAAAAAAAAAAAAAAAAAAA";
s += "BBBBBBBBBBBBBBBBBBBBBBB";
txtOutput.Text = s;

I want to show them like:
AAAAAAAAAAAAAAAAAAAAA
BBBBBBBBBBBBBBBBBBBBBBB

But the output is always in one line:
AAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBB

Even I include a "\n" at the end at the first line:
s = "AAAAAAAAAAAAAAAAAAAAA\n";

Thanks

Nov 16 '05 #3
Chison <sh******@iris-system.com> wrote:
1. String s;
s = @"AAAAAAAAAAAAAAAAAAAAA
BBBBBBBBBBBBBBBBBBBBBBB";
txtOutput.Text = s;
This'll give you a newline and several spaces.
2. String s;
s = "AAAAAAAAAAAAAAAAAAAAA";
s += "\nBBBBBBBBBBBBBBBBBBBBBBB";
txtOutput.Text = s;


This won't give you a newline. Use "\r\n".
Nov 16 '05 #4
Gerald Baeck <ge****@baeck.at> wrote:
s = "AAAAAAAAAAAAAAAAAAAAA" + Environment.NewLine;
s += "BBBBBBBBBBBBBBBBBBBBBBB";


Here're a couple of notes about using "\r\n" instead:
<http://tinyurl.com/4pxg9>.

Also note that such string concatenation is inefficient. Using something
like the following would've been better:

s = "AAAAAAAAAAAAAAAAAAAAA" + Environment.NewLine +
"BBBBBBBBBBBBBBBBBBBBBBB";

This effects a single call to String.Concat, avoiding the unnecessary
creation of a temporary string object.
Nov 16 '05 #5
C# Learner <cs****@learner.here> wrote:
Gerald Baeck <ge****@baeck.at> wrote:
s = "AAAAAAAAAAAAAAAAAAAAA" + Environment.NewLine;
s += "BBBBBBBBBBBBBBBBBBBBBBB";


Here're a couple of notes about using "\r\n" instead:
<http://tinyurl.com/4pxg9>.

Also note that such string concatenation is inefficient. Using something
like the following would've been better:

s = "AAAAAAAAAAAAAAAAAAAAA" + Environment.NewLine +
"BBBBBBBBBBBBBBBBBBBBBBB";

This effects a single call to String.Concat, avoiding the unnecessary
creation of a temporary string object.


Alternatively, use

s = "AAAAAAAAAAAAAAAAAAAAA"+"\r\n"+
"BBBBBBBBBBBBBBBBBBBBBBB";

so that the compiler does all the concatenation, rather than the
runtime.

I'm slightly wary of using Environment.NewLine for text boxes - as I
understand it, it's really what the operating system sees as the
default newline string for files, which may not be what text boxes need
to use. (For instance, I'm not sure what a Mono port of TextBox would
use - it might use \r\n for compatibility with code developed on
Windows, but then that would break if you used Environment.NewLine...

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: chin | last post by:
Hi, I am trying to retrieved the value of the textarea with the newline preserved without having to submit the form to the server. Does anyone knows how to? I tried soft and hard wrap but both...
6
by: john bailo | last post by:
How do create a new line in a text box. If I put \n in my string, and set .Text to the value of the string, a carriage return character is displayed literally, but it doesn't actually start on a...
7
by: Rein Petersen | last post by:
Hi All, I'm having a heckuva time trying to append lines into my multiline readonly System.Windows.Forms.TextBox I was expecting to simply do this: myTextBox.Text += "appending this line...
3
by: IceColdFire | last post by:
Hi, I am using statements of type TxtBox.Text="Hello \n Hi" But they appear in same line with special character. How to make display in TextBox in different lines.... Thanks C# Pro
0
by: Vasco Lohrenscheit | last post by:
Hello, i can convert between the different string types (String constructor and Marshal::StringToHGlobalAnsi), but have problems with endline '\n'. It seems that System::String needs "\r\n"...
29
by: runningdog | last post by:
Hi, I would like to be able to embed a newline in a text string. Is there any convienent notation to do this TIA Steve
2
by: S Shulman | last post by:
Hi all One of the textboxes on a form seem to accepts the newline character while the AcceptReturn is set to False. Is there any way to avoid it? Thank you, Shmuel
11
by: rossum | last post by:
I want to declare a const multi-line string inside a method, and I am having some problems using Environment.NewLine. I started out with: class foo { public void PrintStuff() { const...
0
by: Steve K | last post by:
to this newline when an enter key is detected. Update: I tried adding this code: <code> public PMDDataGridViewTextBoxEditingControl() :base() { this.Multiline = true; } </code>
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.