Saturday, January 12, 2008

How to Insert Newline in a Multiline Label or Textbox

1) First thought might be that inserting a line feed "\n" inside your multi-line string will work. But unfortunately not. You have to insert a carriage return and line feed together i.e. "\r\n".

Example: MyLabel.Text = "Line 1\r\nLine2"

will produce:

Line 1
Line 2

2) Alternately for TextBox one can make use of Lines[] array property, like

MyTextBox.Lines[0] = "Line 1";
MyTextBox.Lines[1] = "Line 2";

will also produce the same result as above.

No comments: