In a Forms application I'm displaying log output from a long running command-line application that generated a lot of output. I start the program in the background, and capture its output and currently display it in a TextBox using AppendText. I prefer to only display for example the last 1000 lines. Removing lines from a TextBox is expensive, and a TextBox does not really feels like the best approach for rolling log display.
Any ideas on the best Control to do a rolling log window in Windows Forms?
I used to have listboxes do this kind of thing. You just remove the first line if the line count reaches, say, 1000. If the log line is too long, you could make the listbox a bit wider (depends on the log information and whether it's possible to catch the meaning from the first visible words without horizontal scrolling) and make the horizonal scrollbar visible.
Had the same need and appreciated a lot this help. This is a slightly modified version.
Create a listbox:
In the main thread (in the intial part of the code),put this to store a reference to the UI thread:
Then this is your log method, callable from any thread:
I needed to do this a while ago and the Listbox was the solution. No one will even notice the difference.
very simple solution
for rolling log like console
exactly what I needed. I solved it with the following code which keeps the last added item visible: