C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
C# program that calls AppendText
private void Test()
{
for (int i = 0; i < 2; i++)
{
textBox1.AppendText("Some text");
}
}
Contents of TextBox
Some textSome text
Tip: The Environment type offers the string value that represents a newline. It equals \r\n.
Environment.NewLineC# program that calls AppendTextBoxLine
public partial class Form1 : Form
{
private void AppendTextBoxLine(string myStr)
{
if (textBox1.Text.Length > 0)
{
textBox1.AppendText(Environment.NewLine);
}
textBox1.AppendText(myStr);
}
private void TestMethod()
{
for (int i = 0; i < 2; i++)
{
AppendTextBoxLine("Some text");
}
}
}
Contents of TextBox
Some text
Some text
Program 3: C#
public partial class Browser : Form
{
private void Test()
{
// Will leave a blank line on the end.
for (int i = 0; i < 2; i++)
{
textBox1.AppendText("Some text" + Environment.NewLine);
}
// Will leave a blank line on the start.
for (int i = 0; i < 2; i++)
{
textBox1.AppendText(Environment.NewLine + "Some text");
}
}
}
Tip: Another concept that is useful for when you want to add strings to your TextBox is appending the strings themselves.
String AppendTable 1:
[Some text
Some text
]
Table 2:
[Some text
Some text]