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. faster than: richTextBox1.Select(78,65);richTextBox1.SelectionColor= Color.Red;

faster than: richTextBox1.Select(78,65);richTextBox1.SelectionColor= Color.Red;

Scheduled Pinned Locked Moved C#
question
6 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.
  • E Offline
    E Offline
    ektoras
    wrote on last edited by
    #1

    Is there a faster way to give a specific color in a richTextBox? void makeThisRed(int start, int length) { richTextBox1.Select(start,length); richTextBox1.SelectionColor= Color.Red; }

    D L 2 Replies Last reply
    0
    • E ektoras

      Is there a faster way to give a specific color in a richTextBox? void makeThisRed(int start, int length) { richTextBox1.Select(start,length); richTextBox1.SelectionColor= Color.Red; }

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Nope. That's the fastest way to do it... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      E 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Nope. That's the fastest way to do it... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        E Offline
        E Offline
        ektoras
        wrote on last edited by
        #3

        It is too slow for large richTextBoxes. Maybe using pointers or something else?

        D 1 Reply Last reply
        0
        • E ektoras

          It is too slow for large richTextBoxes. Maybe using pointers or something else?

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          It can't be done using pointers... All RTF formatting is done in-line with the text, kind of like HTML tags. In order for you to change a section of text to a different format, the RTF stream holding all the text and formating information must be rewritten. This means copying everything from the beginning of the RTF stream to the point where you are making your changes, appending the new formatting codes to the copy, append the segment of text you're changing, appending any closing formatting codes that are required, then, finally, appending the remaining original RTF stream. You can't do it using pointers because you have to rewrite the entire RTF stream anyway so it's in one contiguous stream of data. It sounds like, because of performance considerations, that an RTF box wasn't a good choice to fulfill your requirements. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          L 1 Reply Last reply
          0
          • E ektoras

            Is there a faster way to give a specific color in a richTextBox? void makeThisRed(int start, int length) { richTextBox1.Select(start,length); richTextBox1.SelectionColor= Color.Red; }

            L Offline
            L Offline
            leppie
            wrote on last edited by
            #5

            If you want faster RichTextBox coloring, set the color as your append the text. ie

            rtb.SelectionColor = COlor.Magenta;
            rtb.AppendText("Barney");
            rtb.SelectionColor = Color.Black;

            In the end it will still be slow as #$%#. If you want something fast, you will need to write your own editor (like I did). xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots

            1 Reply Last reply
            0
            • D Dave Kreskowiak

              It can't be done using pointers... All RTF formatting is done in-line with the text, kind of like HTML tags. In order for you to change a section of text to a different format, the RTF stream holding all the text and formating information must be rewritten. This means copying everything from the beginning of the RTF stream to the point where you are making your changes, appending the new formatting codes to the copy, append the segment of text you're changing, appending any closing formatting codes that are required, then, finally, appending the remaining original RTF stream. You can't do it using pointers because you have to rewrite the entire RTF stream anyway so it's in one contiguous stream of data. It sounds like, because of performance considerations, that an RTF box wasn't a good choice to fulfill your requirements. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

              L Offline
              L Offline
              leppie
              wrote on last edited by
              #6

              I think we need a sticky post. DONT USE RICHTEXTBOX FOR SYNTAX COLORING! :laugh: xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots

              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