1

I'm currently working on a programming educational software and I still haven't figured out how to colorize some particular words (keywords like if,while,for,using,namespace and so on) in a RICHTEXTBOX.

I've tried this: Readonly richtextbox changing color of keyword C#

but it works only on WinForms. The methods like Action, Select and the properties of the class Color seem not to exist.

Example images: https://i.stack.imgur.com/xsjFP.jpg

HyXzEl
  • 11
  • 3
  • I have done something like [this](https://stackoverflow.com/a/18149516) for a custom syntax highlighter before. Obviously, you'll have to adjust it for your specific case, but this should give you a good start. – eye_am_groot Jul 03 '19 at 17:57
  • nothing helped for now.... I'm researching the topic even more and all I get is dynamic richtextbox as a result (not in xaml code). I want the text to be added by the user. :/ – HyXzEl Jul 04 '19 at 23:11
  • Hmmm... well the question lists "string", "char", and "null" as the keywords they want to highlight, so I'm not sure why following the Q&A wouldn't work for you. Obviously, you'll need to tweak for your specific case, but it seems like it would get you very, very close (unless there is more to your questions than you've listed). – eye_am_groot Jul 05 '19 at 11:02
  • If you want dynamic coloring, this is the way to do it. If you want the highlighting to happen after a button is pushed, adjust from `TextChanged` to the button pushed event. – eye_am_groot Jul 05 '19 at 11:04
  • I'm so sorry, I clicked a different link and then answered you that your link doesn't work. I'm so sorry, the code is working and it solved my problem. Now I have colorization for the string keyword, I'm simply going to adjust the code to all the keywords in the C# programming language and then it will be exactly what I wanted. Thank you very much. You solved my problem <3. The dynamic colorization is currently working. Which is exactly wha I wanted to do. – HyXzEl Jul 07 '19 at 13:51
  • I finished with the blue keywords colorization and now I just have to do the rest coloring for the Methods and other stuff which will basically make me copy&paste the same code with different method name and put the property from the Colors class to Green and once more for yellow and purple for the other keywords and that will be it. Thanks a lot, Greg. :-) – HyXzEl Jul 07 '19 at 22:31
  • No problem! Glad it's solved – eye_am_groot Jul 08 '19 at 11:36
  • I am currently low on reputation as they call it in Stackoverflow so I can't upvote any answers, but you should know if I could I'd upvote yours. Thanks for the quick respond and everything! :)) – HyXzEl Jul 16 '19 at 19:03
  • No problem. Upvotes on comments don't do anything (other than alert future people a comment was useful) so it's all good. Upvote the answer on the link I gave, if you can). – eye_am_groot Jul 17 '19 at 11:11

0 Answers0