How can i add a line of text to a multi-line TextBox?
e.g. pseudocode;
textBox1.Clear();
textBox1.Lines.Add("1000+");
textBox1.Lines.Add("750-999");
textBox1.Lines.Add("400-749");
...snip...
textBox1.Lines.Add("40-59");
or
textBox1.Lines.Append("brown");
textBox1.Lines.Append("brwn");
textBox1.Lines.Append("brn");
textBox1.Lines.Append("brow");
textBox1.Lines.Append("br");
textBox1.Lines.Append("brw");
textBox1.Lines.Append("brwm");
textBox1.Lines.Append("bron");
textBox1.Lines.Append("bwn");
textBox1.Lines.Append("brnw");
textBox1.Lines.Append("bren");
textBox1.Lines.Append("broe");
textBox1.Lines.Append("bewn");
The only methods that TextBox.Lines implements (that i can see) are:
- Clone
- CopyTo
- Equals
- GetType
- GetHashCode
- GetEnumerator
- Initialize
- GetLowerBound
- GetUpperBound
- GetLength
- GetLongLength
- GetValue
- SetValue
- ToString

@Casperah pointed out that i’m thinking about it wrong:
TextBoxdoesn’t have linesThe question then is how to accomplish what i want, rather than what WinForms lets me.
There are subtle bugs in the other given variants:
textBox1.AppendText("Hello" + Environment.NewLine);textBox1.AppendText("Hello" + "\r\n");textBox1.Text += "Hello\r\n"textbox1.Text += System.Environment.NewLine + "brown";They either append or prepend a newline when one (might) not be required.
So, extension helper:
So now:
and
Note: Any code is released into the public domain. No attribution required.