Search code examples
c#textboxmultiline

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


I am using a multiline textbox, and I am getting behavior I cannot fully explain. I use

 textbox.AppendText("line \n"); 

to append a new line to a textbox. When using this 3 times, I get

line 
line 
line

displayed in the textbox. Now, I resize the textbox. The text becomes

line line line 

That is, the newlines disappear. I know I should be using

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

So I know how to solve the problem. I would like to know why, when using "\n", the newlines initially appear, but disappear when resizing.


Solution

  • 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.