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 ?
textBox1.Text += "new Log Message" + Environment.NewLine;
make the texbox not disabled, but readonly and the scrollbar will appear
A better option is to use:
TextBox.AppendText(string)
for example:
myTextBox.AppendText(newLogEntry + Environment.NewLine);
Which makes a multi line textbox scroll to the button as well as to avoid flickering of the scroll bar.
MSDN on TextBox.AppendText(string)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With