Best logging/tty (teletype-style) output control?
-
What is the best approach for showing logged events and data in a window, both in situations where data will always be available a line at a time, and in situations where it won't? One approach is to use a text box with the 'readonly' property enabled, and keep shoving new text at the end. That approach is workable, but the only practical methods of adding data are to either do something like "myTextBox.Text = myTextBox.Text & newStuff", which gets very slow pretty quickly, or else to set the selection point to the end of the text and then do "myTextBox.SelectedText = newStuff", which works better but trashes the positions of the current selection and scroll. Another approach is to use a listbox. This offers some advantages, in that a listbox can perform well with lots of data, and an owner-draw listbox can display data in a variety of nice formats. Unfortunately, a listbox does not provide any good way for people to copy text, nor does it provide any nice way I can find to scroll when new data is added if and only if the scroll position is set to the bottom. Further, I'm not aware of any way to force a listbox to recalculate the height of all the objects therein (e.g. in response to a resize event) other than by deleting and re-adding all of them (which would be needlessly slow, would require extra handling to maintain anything even remotely resembling the current scroll position, etc.) Are there any better alternatives to those types of controls?
-
What is the best approach for showing logged events and data in a window, both in situations where data will always be available a line at a time, and in situations where it won't? One approach is to use a text box with the 'readonly' property enabled, and keep shoving new text at the end. That approach is workable, but the only practical methods of adding data are to either do something like "myTextBox.Text = myTextBox.Text & newStuff", which gets very slow pretty quickly, or else to set the selection point to the end of the text and then do "myTextBox.SelectedText = newStuff", which works better but trashes the positions of the current selection and scroll. Another approach is to use a listbox. This offers some advantages, in that a listbox can perform well with lots of data, and an owner-draw listbox can display data in a variety of nice formats. Unfortunately, a listbox does not provide any good way for people to copy text, nor does it provide any nice way I can find to scroll when new data is added if and only if the scroll position is set to the bottom. Further, I'm not aware of any way to force a listbox to recalculate the height of all the objects therein (e.g. in response to a resize event) other than by deleting and re-adding all of them (which would be needlessly slow, would require extra handling to maintain anything even remotely resembling the current scroll position, etc.) Are there any better alternatives to those types of controls?
Have you considered a listview? For the copy issue, you could enable multi-select and have a context menu that would let the user copy the text of the selected items to the clipboard. If you call the newly added item's http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.ensurevisible.aspx[^], the listview will scroll down automatically.
-
Have you considered a listview? For the copy issue, you could enable multi-select and have a context menu that would let the user copy the text of the selected items to the clipboard. If you call the newly added item's http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.ensurevisible.aspx[^], the listview will scroll down automatically.
I hadn't thought about it for this application. The one time I tried using a ListView, I found it confusing and couldn't figure out what was going on. It does conceptually seem like a ListView might be able to do what I'm after, but it also seems complicated. I don't care about people being able to edit stuff in the log window, but select/copy would be nice. The ListBox is in some ways pretty good; the biggest weaknesses are: (1) I don't know any reasonable way to have it reformat when the control width changes (to allow wordwrap). Not a biggie, and would probably be complicated to make work nicely. (2) I don't know how to make scrolling behave sensibly (e.g. when a new item is added, scroll if the last item was visible but the new item is not; when items have to be pruned from the start of the box (e.g. keeping the last 10,000 lines) maintain the same apparent scroll position unless items on the display are getting deleted. (3) I don't know any nice way to allow text select/copy. Right now I'm using double-click as a shortcut to copy a line to the clipboard, but that's nonstandard and seems ugly. Of those, I'd say #2 is the only one that seems really bothersome. Any ideas how to deal with it?