Microsoft Communities

Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How do I set several lines into a multi-line TextBox?

There are several of ways to do this. Here are a few:

1) Insert a carriage return, linefeed combination, "\r\n", between lines of text.

textBox1.Text = "This is line 1.\r\nThis is line 2";

2) Use the Environment.NewLine property. This property is normally set to "\r\n".

textBox1.Text = "This is line 1." + Environment.NewLine + "This is line 2";

3) Use the Lines property of the TextBox. Make sure you populate your array before you set the property.

string[] arr = new string[2];
arr[0] = "this is line1";
arr[1] = "this is line 2";

textBox3.Lines = arr;

Contributed from George Shepherd's Windows Forms FAQ



Page view counter