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. Improve RichTextBox performance

Improve RichTextBox performance

Scheduled Pinned Locked Moved C#
performancetutorialquestioncode-review
4 Posts 2 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.
  • L Offline
    L Offline
    Latheesan
    wrote on last edited by
    #1

    Hello, I just found out that, my editor made of rtb lags really bad when the number of lines is longer than 100 for example. Could it be because im using the syntax highlighting textbox library to highlight syntax inside the editor? Is it possible to increase the performance of it somehow so it doesnt lag ever sec as you type.

    L 1 Reply Last reply
    0
    • L Latheesan

      Hello, I just found out that, my editor made of rtb lags really bad when the number of lines is longer than 100 for example. Could it be because im using the syntax highlighting textbox library to highlight syntax inside the editor? Is it possible to increase the performance of it somehow so it doesnt lag ever sec as you type.

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

      I am not surprised since a textbox is holding all its data in one string; doing anything fancy to it does not scale well, it is at least quadratic: when the text grows, so does the number of operations required, AND the cost of each operation (creating a new string copying all the characters). I see no easy way out; I did my own line-oriented text editor (with syntax highlighting and everyting) in a plain Panel; and I do all screen-based logging to a ListBox. I am not a big fan of either TextBoxes or RichTextBoxes because of their degrading performance. I only use them for short texts (say 50 lines), and preferably texts that dont change. :)

      Luc Pattyn [My Articles] [Forum Guidelines]

      L 1 Reply Last reply
      0
      • L Luc Pattyn

        I am not surprised since a textbox is holding all its data in one string; doing anything fancy to it does not scale well, it is at least quadratic: when the text grows, so does the number of operations required, AND the cost of each operation (creating a new string copying all the characters). I see no easy way out; I did my own line-oriented text editor (with syntax highlighting and everyting) in a plain Panel; and I do all screen-based logging to a ListBox. I am not a big fan of either TextBoxes or RichTextBoxes because of their degrading performance. I only use them for short texts (say 50 lines), and preferably texts that dont change. :)

        Luc Pattyn [My Articles] [Forum Guidelines]

        L Offline
        L Offline
        Latheesan
        wrote on last edited by
        #3

        How can i create a line-oriented text editor of my own with syntax highlighting ability?

        L 1 Reply Last reply
        0
        • L Latheesan

          How can i create a line-oriented text editor of my own with syntax highlighting ability?

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

          If you are not happy with what you have, I can tell you how I did it, but I must warn you, it has been a big effort. I did it as part of a larger project; relevant steps include: - text lines stored in memory basically in an ArrayList, one item per line; - each line also holds two flags to indicate comment status; these get set when the line is input/changed; - text drawn in a Panel, using OnPaint handler, and Graphics.DrawString; - all coloring/syntax highlighting handled inside OnPaint, based on a simple parser that knows the list of keywords (and their color) for each of the supported programming languages. Steps taken to get maximum performance: - only the visible lines are parsed, colored and painted; lines scrolled outside the panel are skipped (except for the comment flags). A typical Panel shows up to 60 lines, a very small number with respect to an entire source file. - the comment flags help in starting the first visible line either as continued comment (green background) or not. - the simple parsers are not full fledged parsers, they dont understand expressions, dont return a parse tree, etc. They must only process a single line and know about comments, string literals, and keywords. - the parsers return tokens (identifiers, constants, operators, etc) as a string plus Color; Graphics.DrawString paints these tokens individually. - as a result of all this, nearly linear behavior, and no delay whatsoever. All in all a couple thousand lines of C# code (and based on a growing library of low-level classes that I use in all my apps and that is not included in the estimate). Hope this clarifies things. :)

          Luc Pattyn [My Articles] [Forum Guidelines]

          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