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. RichTextBox Selection color problem

RichTextBox Selection color problem

Scheduled Pinned Locked Moved C#
questionhelp
2 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.
  • R Offline
    R Offline
    Radu Sorin
    wrote on last edited by
    #1

    As short as i can explain... I have a RichTextBox that i want to use for syntax highlighting. For coloring i use: richControl.Select(...); richControl.SelectionColor= ...; and it works . The text is highlighted using a list of keywords. Lets say that I have te following line in my textbox: I like icecream In this line "like" is a keyword and its color is red(for explanation sake) and all the other words are black. THE PROBLEM is that if I move the caret just after the word "like" and I start typing, the new inputed characters will also be red,and i wanted them to be black. How can i escape this problem?

    M 1 Reply Last reply
    0
    • R Radu Sorin

      As short as i can explain... I have a RichTextBox that i want to use for syntax highlighting. For coloring i use: richControl.Select(...); richControl.SelectionColor= ...; and it works . The text is highlighted using a list of keywords. Lets say that I have te following line in my textbox: I like icecream In this line "like" is a keyword and its color is red(for explanation sake) and all the other words are black. THE PROBLEM is that if I move the caret just after the word "like" and I start typing, the new inputed characters will also be red,and i wanted them to be black. How can i escape this problem?

      M Offline
      M Offline
      mav northwind
      wrote on last edited by
      #2

      That's the regular behaviour you get in every text editor under windows that allows for formatted text. If you really want to do syntax highlighting in your RTB yourself (although there are several articles here on this topic), you should reconsider when to perform colorization. If you do it whenever the text is changed or when a key is pressed, then you'll find out that like + the letter you typed isn't a keyword anymore, so the whole word should be black.

      Regards, mav -- Black holes are the places where god divided by 0...

      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