In this tutorial, we’ll learn How to add newline in a TextBox Control.
Normally, when you want to add newline to a string you can use’\n’ for adding new lines like below.
Example:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | using System; using System.Collections.Generic; using System.Data; using System.Text; using System.Windows.Forms; namespace FirstProgram { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { string sample = "C# \n Tutorials \n with\n Examples"; MessageBox.Show(sample); txtSample.Text = sample; } } } |
Output: (In Message box only)

In Message box you can see the newline but not in the text box.

If you want to add newline for a text box, you can not simply use ‘\n’, rather you can use Environment.NewLine.
1 2 3 4 5 6 7 8 9 | private void Form1_Load(object sender, EventArgs e) { string sample = "C#\nTutorials\nwith\nExamples"; MessageBox.Show(sample); string newLine = Environment.NewLine; txtSample.Text = "C#" + newLine + "Tutorials" + newLine + "with" + newLine + "Examples"; } |
Output:
