How To Add A New Line in a C# or Visual Basic TextBox
10 Comments Published by Steven 4 years, 8 months ago in C#If you're building a Windows Form Application, for example with C# or Visual Basic, then you may need to add a new line character, for example in a multiline TextBox. You do this using Enviroment.NewLine to insert the line break as follows:
CODE:
-
textBox1.Text="First Line" + Environment.NewLine + "Second Line";
My preferred use is with the += operator in C#:
CODE:
-
textBox1.Text = "Line One";
-
textBox1.Text += Environment.NewLine;
-
textBox1.Text += "Line Two";
This way, you can add extra lines of output to the TextBox as you require it.
References: Environment.NewLine on MSDN
10 Responses to “How To Add A New Line in a C# or Visual Basic TextBox”
Leave a Reply
You must log in to post a comment.
Search
Categories
- ASP (3)
- ASP Basics (3)
- Blogs (2)
- C# (1)
- Firefox (1)
- Flash (1)
- Google (6)
- Hacks (3)
- Java (1)
- PHP (12)
- Basics (8)
- Files (1)
- Image Handling (3)
- Ruby (1)
- Tips (10)
- Web Hosting (3)
- Web Hosting Articles (1)
- Web Hosting News (2)
- Windows (6)
- Wordpress (2)
Related Entries
- No related posts.
Hey,
Thats a good one …
Excellent – just what I was looking for! Thanks
Fast and clean.
Many thanks!
Thx!! I really needed this! great
Thata was simple but hard to find
Thnxs , just what I need!
Really it is excellent.Bez i was thinking for more hours but easily i found this!
Yeahh. But not working un vb 6
easier even is just vbNewLine in Visual Basic
textBox1.Text=”First Line” vbNewLine “Second Line”
It’s working in VB 9.0
Very Thanks to Webmasters.
But about JDuarte solving, the correct code in VB 9.0 is:
TextBox1.Text = “First Line” vbNewLine “Second Line”
however it’s good and easier.