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. Visual Basic
  4. Get the last line from a constantly updating textbox

Get the last line from a constantly updating textbox

Scheduled Pinned Locked Moved Visual Basic
question
13 Posts 4 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.
  • T Offline
    T Offline
    The Mighty Atom
    wrote on last edited by
    #1

    Hi. I have a textbox that is constantly updated line by line from a process.startinfo... thingy. The text pasted in the textbox is actully console application output. What i need is a string variable that always holds the last line from the textbox when its updating (new lines are added). Does anyone know how i can do that?

    http://www.themightyatom.nl

    L J 2 Replies Last reply
    0
    • T The Mighty Atom

      Hi. I have a textbox that is constantly updated line by line from a process.startinfo... thingy. The text pasted in the textbox is actully console application output. What i need is a string variable that always holds the last line from the textbox when its updating (new lines are added). Does anyone know how i can do that?

      http://www.themightyatom.nl

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

      Hi, assuming your other process is outputting lines of text (lines separated by NewLine) then it isn't very wise to (1) concatenate all of them since that is what a TextBox needs, and (2) then try to find the last line again. For starters, remember the most recent line where it comes in (maybe in a Process.OutputDataReceived handler?) i.e. before it gets concatenated; and then maybe drop the Textbox, i.e. if you are not relying on the wrapping capabilities of a textbox, then use a ListBox instead. It is both easier and faster. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


      T 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, assuming your other process is outputting lines of text (lines separated by NewLine) then it isn't very wise to (1) concatenate all of them since that is what a TextBox needs, and (2) then try to find the last line again. For starters, remember the most recent line where it comes in (maybe in a Process.OutputDataReceived handler?) i.e. before it gets concatenated; and then maybe drop the Textbox, i.e. if you are not relying on the wrapping capabilities of a textbox, then use a ListBox instead. It is both easier and faster. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


        T Offline
        T Offline
        The Mighty Atom
        wrote on last edited by
        #3

        Well, the process that im running is a compilation process with its output redirected to a textbox, and i'd like to use regular expressions later to colorize error and warning messages. I already have a sub that is fired when a new line is added to the textbox, i just need a string variable to hold the last pasted line. I need to compare something. Its hard to explain, unless you know what level design for the game Half-Life is all about... :) Ill experiment with a listbox.

        http://www.themightyatom.nl

        L 1 Reply Last reply
        0
        • T The Mighty Atom

          Well, the process that im running is a compilation process with its output redirected to a textbox, and i'd like to use regular expressions later to colorize error and warning messages. I already have a sub that is fired when a new line is added to the textbox, i just need a string variable to hold the last pasted line. I need to compare something. Its hard to explain, unless you know what level design for the game Half-Life is all about... :) Ill experiment with a listbox.

          http://www.themightyatom.nl

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

          Hi, if your ListBox output needs some formatting, then you have to paint the content yourself: switch its DrawMode to one of the "OwnerDrawn" values and provide a DrawItem handler, wich can be as simple as

          public void lb_DrawItem(object sender, DrawItemEventArgs e) {
          ListBox lb=sender as ListBox;
          int index=e.Index;
          if (index<0 || index>=lb.Items.Count) return;
          string s=(string)lb.Items[index];
          // Draw the background of the ListBox control for each item.
          e.DrawBackground();
          g.DrawString(s, font, brush, e.Bounds);
          }

          assuming each line uses a single format (you need to provide some font and brush; if you create them inside the DrawItem handler, don't forget to dispose them too). BTW: one nice characteristic of the ListBox is it only calls DrawItem for the lines that are actually visible, so when thousands of lines are present, but only 25 or so are visible at any given time, only those 25 will fire the DrawItem colorization and painting. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


          1 Reply Last reply
          0
          • T The Mighty Atom

            Hi. I have a textbox that is constantly updated line by line from a process.startinfo... thingy. The text pasted in the textbox is actully console application output. What i need is a string variable that always holds the last line from the textbox when its updating (new lines are added). Does anyone know how i can do that?

            http://www.themightyatom.nl

            J Offline
            J Offline
            Jarno Burger
            wrote on last edited by
            #5

            what did for my debugger , put every given string in a array with a fixed length. when there was a new string , i fisrt moved every string one position in the array , meaning that the first one would be dumped. FIFO. a array with strings was a lot easier to edit/view. you could also use a queue , but i love to build stuff myself , loving hobby code :)

            Jarno Burger Video Jockey

            T 1 Reply Last reply
            0
            • J Jarno Burger

              what did for my debugger , put every given string in a array with a fixed length. when there was a new string , i fisrt moved every string one position in the array , meaning that the first one would be dumped. FIFO. a array with strings was a lot easier to edit/view. you could also use a queue , but i love to build stuff myself , loving hobby code :)

              Jarno Burger Video Jockey

              T Offline
              T Offline
              The Mighty Atom
              wrote on last edited by
              #6

              Hmmm... this is tough. I tried a listbox to display the output, and it works fine, even better than a textbox. But what really annoys me is that a listbox does not allow you to colorize specific items (fore and backcolor). It also flickers like crazy. So was thinking, are there custom listbox controls out there with the exact same functionalities is the stock listbox, only with the added ability to colorize the backcolor and/or forecolor of specific listbox items? I google like crazy today but found squat.

              http://www.themightyatom.nl

              modified on Thursday, May 28, 2009 12:51 PM

              D 1 Reply Last reply
              0
              • T The Mighty Atom

                Hmmm... this is tough. I tried a listbox to display the output, and it works fine, even better than a textbox. But what really annoys me is that a listbox does not allow you to colorize specific items (fore and backcolor). It also flickers like crazy. So was thinking, are there custom listbox controls out there with the exact same functionalities is the stock listbox, only with the added ability to colorize the backcolor and/or forecolor of specific listbox items? I google like crazy today but found squat.

                http://www.themightyatom.nl

                modified on Thursday, May 28, 2009 12:51 PM

                D Offline
                D Offline
                DidiKunz
                wrote on last edited by
                #7

                I don't think there are such list boxes. I would stay with the textbox or use Scintilla.NET http://www.codeplex.com/ScintillaNET[^] it has syntax colloring built in. To get the last line, search backwards to the first cr/lf and you got your line. Good luck: Didi

                T 1 Reply Last reply
                0
                • D DidiKunz

                  I don't think there are such list boxes. I would stay with the textbox or use Scintilla.NET http://www.codeplex.com/ScintillaNET[^] it has syntax colloring built in. To get the last line, search backwards to the first cr/lf and you got your line. Good luck: Didi

                  T Offline
                  T Offline
                  The Mighty Atom
                  wrote on last edited by
                  #8

                  Yeah i think so, i already found a custom listbox control that supports item colors, but it flickers like crazy when items are added in a short timespan. Ill try that ScintillaNET thingy. If i understand correctly, this is a pack with new/updated controls with new features?

                  http://www.themightyatom.nl

                  D 1 Reply Last reply
                  0
                  • T The Mighty Atom

                    Yeah i think so, i already found a custom listbox control that supports item colors, but it flickers like crazy when items are added in a short timespan. Ill try that ScintillaNET thingy. If i understand correctly, this is a pack with new/updated controls with new features?

                    http://www.themightyatom.nl

                    D Offline
                    D Offline
                    DidiKunz
                    wrote on last edited by
                    #9

                    You could use BeginUpdate and EndUpdate on your control before and after the adding of items (that works on most controls). Yes Scintilla.NET is a pack with controls in it... Regards: Didi

                    T 1 Reply Last reply
                    0
                    • D DidiKunz

                      You could use BeginUpdate and EndUpdate on your control before and after the adding of items (that works on most controls). Yes Scintilla.NET is a pack with controls in it... Regards: Didi

                      T Offline
                      T Offline
                      The Mighty Atom
                      wrote on last edited by
                      #10

                      I tried the beginupdate and endupdate, but i want the user to actually see the process. As for Scintilla.NET, it only adds four unkown controls to the toolbox. I don't know how i could use that with my textbox. Plus, it makes my Visual Studio crash. :/

                      http://www.themightyatom.nl

                      D 1 Reply Last reply
                      0
                      • T The Mighty Atom

                        I tried the beginupdate and endupdate, but i want the user to actually see the process. As for Scintilla.NET, it only adds four unkown controls to the toolbox. I don't know how i could use that with my textbox. Plus, it makes my Visual Studio crash. :/

                        http://www.themightyatom.nl

                        D Offline
                        D Offline
                        DidiKunz
                        wrote on last edited by
                        #11

                        you don't use it with your textbox, but instead of. Find documentation on Scintilla Documentation[^] Scintilla.Net is a wraper of Scintilla, a c++ rich text control with sintax highliting etc. What exactly do you do, just before your VS crashes?

                        T 1 Reply Last reply
                        0
                        • D DidiKunz

                          you don't use it with your textbox, but instead of. Find documentation on Scintilla Documentation[^] Scintilla.Net is a wraper of Scintilla, a c++ rich text control with sintax highliting etc. What exactly do you do, just before your VS crashes?

                          T Offline
                          T Offline
                          The Mighty Atom
                          wrote on last edited by
                          #12

                          Nevermind, im not going to use it, too complicated for me. :( Ill just stick to a richtextbox. If i just could find a way to get the last line of that constantly updating textbox, i may just get it to work. Syntax highlighting using regex isn't the problem, i know how to do it.

                          http://www.themightyatom.nl

                          D 1 Reply Last reply
                          0
                          • T The Mighty Atom

                            Nevermind, im not going to use it, too complicated for me. :( Ill just stick to a richtextbox. If i just could find a way to get the last line of that constantly updating textbox, i may just get it to work. Syntax highlighting using regex isn't the problem, i know how to do it.

                            http://www.themightyatom.nl

                            D Offline
                            D Offline
                            DidiKunz
                            wrote on last edited by
                            #13

                            To get the last line, search backwards to the first cr/lf and you got your line. Find info here[^] Good luck: Didi

                            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