Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
How to add new line in textbox without repalcing existing text after pressing a button in C# ?
Posted
Comments
Sergey Alexandrovich Kryukov 27-Jan-12 12:15pm    
A suggestion to all experts:

We should stop attempting to answer any questions if OP does not properly specify type of application, UI library and other relevant detail which would exclude this kind of confusion. All type mentioned in the question should be written in fully-qualified form. We should request it and only answer when OP comply. Multiple failures to specify such detail became a curse of this forum.

--SA
[no name] 27-Jan-12 12:25pm    
You could try holding your breath also.

If they irritate you so much then simple. DON'T ANSWER!!
Sergey Alexandrovich Kryukov 30-Jan-12 2:22am    
You did not get it. I do not answer in such cases. I suggest others do not answer. Are you against it?
--SA
Sergey Alexandrovich Kryukov 27-Jan-12 12:15pm    
You need to specify exact type of text box. There are more then one. And tag your UI library.

The solution is pretty simple: manipulate selection.
--SA

hi,

In order to add new line, first you need to set the textbox mode to MultiLine. Here is an example.

C#
TextBox1.TextMode = TextBoxMode.MultiLine;
TextBox1.Text = "First Line" + Environment.NewLine + "Second Line";
TextBox1.Text += "\nThird Line\r\nFourth Line";


The results will look like

First Line
Second Line
Third Line
Fourth Line
 
Share this answer
 
Comments
Wonde Tadesse 27-Jan-12 13:47pm    
5+
Bryian Tan 27-Jan-12 16:00pm    
Thanks :)
You can use StringBuilder[^] class AppendLine[^] functionality. Look the example at the bottom of the article.
 
Share this answer
 
v2
C#
TextBox1.Text += " learn to use Google";
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900