Chuck Bowling <ch**********@sbcglobal-NO-SPAM.net> wrote:
How do I do a newline? i.e., assigning a string to a textbox...
txt.Text = "My first line...\n My second line...\n My third line...";
Ok... the newline character works in a string... apparently it just doesn't
get displayed in a textbox control...
Anybody have a clue what's going on? I have the textbox Multiline and
acceptsReturn properties set to True. What am I missing?
You need to use \r\n instead of \n between lines. For instance:
using System;
using System.Windows.Forms;
using System.Drawing;
public class Test : Form
{
Test()
{
Size = new Size(200,200);
TextBox tb = new TextBox();
tb.Size = new Size (150, 150);
tb.Text = "First line\nSecond line\r\nThird line";
tb.Multiline = true;
Controls.Add(tb);
}
static void Main()
{
Application.Run(new Test());
}
}
comes up with
First line Second line
Third line
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too