Add a New Line in a C# or Visual Basic TextBox

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:

textBox1.Text = "First Line" + Environment.NewLine + "Second Line";

My preferred use is with the += operator in C#:

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



The latest posts sent straight to your inbox.