Why do c# textbox.AppendText() newlines disappear when using \n as line terminator?

On resizing, that "\n" character gets removed, as resizing also controls the new line creation and deletion based on "\n", System.Env.NewLine never gets omit.


Rather than a line that looks like this:

textbox.AppendText("line \n"); 

you should use this line instead:

textbox.AppendText("line "+ Environment.NewLine);

This occurs because the newline for unix is \n, but for non-unix (i.e. Windows) it is \r\n. When the box is resized, the system newline is replaced, thus if you have only \n, it will be lost in the resize.

Reference: MSDN: Environment.NewLine Property