How to display multilines in textbox

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

Hi,

Here is the code:

this.textBox1.AcceptsReturn = true;
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.ReadOnly = true;
this.textBox1.ScrollBars =
System.Windows.Forms.ScrollBars.Both;
this.textBox1.Size = new System.Drawing.Size(552, 296);
this.textBox1.TabIndex = 0;
this.textBox1.Text = DateTime.Now + " hello ....." +
Environment.NewLine;
this.textBox1.TextChanged += new System.EventHandler
(this.textBox1_TextChanged);

private void timer1_Tick(object sender, System.EventArgs e)
{
this.textBox1.Text = DateTime.Now + " welcome ....." +
Environment.NewLine;
}

I want to display the text in the text box like the
following:

DateTime hello
DateTime welcome
DateTime welcome
DateTime welcome
DateTime welcome
DateTime welcome
DateTime welcome
DateTime welcome
DateTime welcome
.....

Environment.NewLine seems does not work. How can I do
that?

Thanks
 
DateTime.Now + " welcome... \r\n";

It does not work.

There is only a single line displaying in the multiline textbox. The
single line keeps on updating with the timer.
 
Surely you meant to do this....

private void timer1_Tick(object sender, System.EventArgs e)
{
this.textBox1.Text += DateTime.Now + " welcome ....." +
Environment.NewLine;
}
 
Environment.NewLine is only a constant that equals "\r\n"

if "\r\n" doesn't work, nor will the constant.

Dan.

Surely you meant to do this....

private void timer1_Tick(object sender, System.EventArgs e)
{
this.textBox1.Text += DateTime.Now + " welcome ....." +
Environment.NewLine;
}
 
Gareth's right, you're not appending the text.

Surely you meant to do this....

private void timer1_Tick(object sender, System.EventArgs e)
{
this.textBox1.Text += DateTime.Now + " welcome ....." +
Environment.NewLine;
}
 
Back
Top