Search code examples
c#winformstextbox

C# Textbox, how to set a specific color for a specific word


I've been wondering how do I do that if I type "Hello" to textbox, it's color will be set to yellow, however if I type "GoodBoy" that specific word will get red.

Is there a way in C# WinForms how to set a color of specific words in textbox whenever you type them. I only know how to change the textbox font color but that always sets the color of all characters in that textbox, so is there a way to set color of a word individually?

Thank you for help.


Solution

  • I didn't used C# WinForms for a while, but as I remember you have object aka RichTextBox which allows you to do more things (and use more then one style for your text).

    You will find more info in this link: RichTextBox.SelectedText

    Good luck