How do I set several lines into a multiline textbox

Platform: WinForms| Category: TextBox

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

1) Insert a carriage return-linefeed, ‘\r\n’, between your lines.

		textBox1.Text = 'This is line 1.\r\nThis is line 2';
		// or textBox1.Text = stringvar1 + '\r\n' + stringvar2;

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;

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.