Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Using a TextBox as Console replacement.

Using a TextBox as Console replacement.

Scheduled Pinned Locked Moved C#
questioncsharpc++winformsdesign
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mr Brainley
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • M Mr 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

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      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:


      L 1 Reply Last reply
      0
      • L Luc Pattyn

        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:


        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        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

        L 1 Reply Last reply
        0
        • L Lost User

          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

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          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:


          M 1 Reply Last reply
          0
          • L Luc Pattyn

            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:


            M Offline
            M Offline
            Mr Brainley
            wrote on last edited by
            #5

            Thanks for your help !

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups