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. Coloring string when painting text

Coloring string when painting text

Scheduled Pinned Locked Moved C#
graphicsregexjsonperformancetutorial
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.
  • C Offline
    C Offline
    Chris Copeland
    wrote on last edited by
    #1

    Hey guys, I'm trying to create a control which simply colors certain words in a string, when printed onto a control. For example: "This is a test statement to test the highlighting's ability to test." In this statement, when printed on a control, I need all the words "test" being highlighted in say, blue, while the rest of the string remains the regular color. I've been trying to figure out an effective way of doing this for a long time. I have a graphics buffer, double buffering and some intensive graphic's performance boosting codes in place, but i'm trying not to implement nests of loops just to highlight words. Can anyone point me in the right direction with this? I've been using Regex to find patterns (replacing 'test' with '\C[0,0,255]test') and then converting the '\C[x,y,z]' into a color and looping through word by word, and nesting inside letter by letter, but this is too intensive and simply won't work. Thanks :)

    L 1 Reply Last reply
    0
    • C Chris Copeland

      Hey guys, I'm trying to create a control which simply colors certain words in a string, when printed onto a control. For example: "This is a test statement to test the highlighting's ability to test." In this statement, when printed on a control, I need all the words "test" being highlighted in say, blue, while the rest of the string remains the regular color. I've been trying to figure out an effective way of doing this for a long time. I have a graphics buffer, double buffering and some intensive graphic's performance boosting codes in place, but i'm trying not to implement nests of loops just to highlight words. Can anyone point me in the right direction with this? I've been using Regex to find patterns (replacing 'test' with '\C[0,0,255]test') and then converting the '\C[x,y,z]' into a color and looping through word by word, and nesting inside letter by letter, but this is too intensive and simply won't work. Thanks :)

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

      Hi, a simple way to get this would be by using a RichTextBox; you can add text, select parts of it, and modify attributes (such as ForeColor) for selected text. another way could be to have a Panel and paint all the text yourself in the Paint handler, using Graphics.DrawString with a Font and a Brush (hence color) you choose. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


      Prolific encyclopedia fixture proof-reader browser patron addict?
      We all depend on the beast below.


      C 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, a simple way to get this would be by using a RichTextBox; you can add text, select parts of it, and modify attributes (such as ForeColor) for selected text. another way could be to have a Panel and paint all the text yourself in the Paint handler, using Graphics.DrawString with a Font and a Brush (hence color) you choose. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        Prolific encyclopedia fixture proof-reader browser patron addict?
        We all depend on the beast below.


        C Offline
        C Offline
        Chris Copeland
        wrote on last edited by
        #3

        Well i'm trying to avoid using an RTFBox. It has some handy functions, but i'm really trying to focus on using this control without being dependant on the RTFBox. I might just need to find a much more efficient way to process the highlighted words in a string of text.

        L 1 Reply Last reply
        0
        • C Chris Copeland

          Well i'm trying to avoid using an RTFBox. It has some handy functions, but i'm really trying to focus on using this control without being dependant on the RTFBox. I might just need to find a much more efficient way to process the highlighted words in a string of text.

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

          when I create a text editor, I use a Panel and draw everything myself. Syntax coloring means looking for keywords and some delimiters and using some colors. For an IDE, texts are line oriented, so things are pretty much local; and the big trick is to only compute lines that are visible, which is say 50 lines out of a file that could span hundreds or thousands of lines. If you want more specific help, you'll have to provide some concrete information; so far you have been very vague! FYI: I avoid Regex when performance is important; IMO most of the time Regex offers comfort at the expense of speed. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


          Prolific encyclopedia fixture proof-reader browser patron addict?
          We all depend on the beast below.


          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