Using a TextBox as Console replacement.
-
Hello everyone ! I want to write a simple Winforms UI that uses a textbox to output logmessages. This is quite simple, and i have it up and running, but since i am new to C# and Winforms i was wondering what the recommended way/best practice for this problem is. Right now i just write the logmessages into a StringBuilder and update the Text-property of the TextView everytime a new message is added. Deleting older messages is not yet implemented but simple enough. I know that in MFC i could bind the text property to a string and it would be automatically updated both ways. How do i got about that in C#/Winforms ? I know this is a very general question. I do not want a full answer here, just some hints and pointers where to look, since i am at a loss here (i looked up DataBinding on MSDN, but they only talk about DataBases). Thanks, Brainley
-
Hello everyone ! I want to write a simple Winforms UI that uses a textbox to output logmessages. This is quite simple, and i have it up and running, but since i am new to C# and Winforms i was wondering what the recommended way/best practice for this problem is. Right now i just write the logmessages into a StringBuilder and update the Text-property of the TextView everytime a new message is added. Deleting older messages is not yet implemented but simple enough. I know that in MFC i could bind the text property to a string and it would be automatically updated both ways. How do i got about that in C#/Winforms ? I know this is a very general question. I do not want a full answer here, just some hints and pointers where to look, since i am at a loss here (i looked up DataBinding on MSDN, but they only talk about DataBases). Thanks, Brainley
Hi, I recommend using a ListBox instead of a TextBox when ever the content is line oriented. A TextBox is meant to hold one piece of text, and it effectively stores a single string, which would be the (expensive) concatenation of all your individual log messages. A ListBox on the other hand is aimed at displaying and manipulating lists, that could be lists of single-line strings. Nothing gets concatenated, all items in the list are kept separately, and they can be added, removed, modified, etc. Much easier, and much faster, especially when the total size of the contents increases. I have been using ListBoxes holding millions of messages; I can't imagine getting satisfactory results from a TextBox for such work loads. A StringBuilder would not solve the performance problem at all. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Fixturized forever. :confused:
-
Hi, I recommend using a ListBox instead of a TextBox when ever the content is line oriented. A TextBox is meant to hold one piece of text, and it effectively stores a single string, which would be the (expensive) concatenation of all your individual log messages. A ListBox on the other hand is aimed at displaying and manipulating lists, that could be lists of single-line strings. Nothing gets concatenated, all items in the list are kept separately, and they can be added, removed, modified, etc. Much easier, and much faster, especially when the total size of the contents increases. I have been using ListBoxes holding millions of messages; I can't imagine getting satisfactory results from a TextBox for such work loads. A StringBuilder would not solve the performance problem at all. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Fixturized forever. :confused:
Agree with Luc, use a ListView, change the view to detail, add a single column, and make de column width be the same as the listView (you may handle the onResize event of the listview to make it work ok) You can use a rich text box too but will be more complicated to delete all data
Saludos!! ____Juan
-
Agree with Luc, use a ListView, change the view to detail, add a single column, and make de column width be the same as the listView (you may handle the onResize event of the listview to make it work ok) You can use a rich text box too but will be more complicated to delete all data
Saludos!! ____Juan
To put things straight, I mentioned ListBox, not ListView (maybe ListView can be as performant as ListBox, but I am sure ListBox is the easiest one to use). And RichTextBox is in no way easier or cheaper to use for line-oriented output as a standard TextBox is. BTW if I need minor formatting (say optional styles such as bold, or a few colors, then I turn the ListBox into an OwnerDrawn one, and either store strings with a special first character, or store objects of a very simple class holding text plus some style flags. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Fixturized forever. :confused:
-
To put things straight, I mentioned ListBox, not ListView (maybe ListView can be as performant as ListBox, but I am sure ListBox is the easiest one to use). And RichTextBox is in no way easier or cheaper to use for line-oriented output as a standard TextBox is. BTW if I need minor formatting (say optional styles such as bold, or a few colors, then I turn the ListBox into an OwnerDrawn one, and either store strings with a special first character, or store objects of a very simple class holding text plus some style flags. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Fixturized forever. :confused:
Thanks for your help !