tags:

views:

389

answers:

3

I am quite new to C# (I had an RS-232 problem recently) and am trying to write an small application which does various tasks behind the scenes and I want to create a log of messages to keep the user updated on what stage the application is at.

The log will just consist of simple one line messages.

I am currently using a textbox that is disabled so that the user cannot change it. I can obviously do multiple text lines using the \r\n characters at the end of a line, but when I come to write a 2nd set of messages they are written at the begining of the text box overwriting the first messages.

Can I change this to append rather than overwrite ? Also, will the text box automatically add a scroll barr when the text is more than the box can display ?

+1  A: 
textBox1.Text +=  "new Log Message" + Environment.NewLine;

make the texbox not disabled, but readonly and the scrollbar will appear

ArsenMkrt
All worked great and i had to enable the textbox otherwise the scrollbar wouldnt move, but read only sorted that out too !Thanks all !! Brilliant.
George
you are welcome ;)
ArsenMkrt
There is a problem here. When the first log entry is added, there will be an empty newline at the start.
erelender
it is not difficult to correct erelender
ArsenMkrt
If only i had enough reputation to edit.
erelender
Thats not much of a problem to work around.
George
Nope the first line is used as intended !
George
+2  A: 

To add it at the top:

textBox.Text = newText + Environment.NewLine + textBox.Text;

To append it:

textBox.Text += Environment.NewLine + newText;

Yes, a scroll bar is added automatically.

Austin Salonen
+2  A: 

You can append to the text using this piece of code:

myTextBox.Text += myLogText + Environment.NewLine;

Alternatively, you can use a ListBox.

erelender