To add newline in a text box control in C#

Normally, when you want to add newline to a string you can use'\n' for adding new lines like below.

using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace FirstProgram
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            string sample = "I am \n coming \n from \n Forget Code";
            MessageBox.Show(sample);
         txtSample.Text = sample;
        }
    }
}


Output: (In Message box only)
I am
coming
from
Forget Code


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.

using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace FirstProgram
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            string sample = "I am \n coming \n from \n Forget Code";
            MessageBox.Show(sample);

            string newLine = Environment.NewLine;

            txtSample.Text = "I am"+newLine+"coming"+newLine+" from " +newLine+ "Forget Code";
        }
    }
}


Output: (Both in Message box and text box)

I am
coming
from
Forget Code