Greetings!
I just want to ask on how to change a word to another word and change its color in a textbox. For example if I type the word "Yes" in the text box it will change to "NO" and change its color into red at the same time.

You can do a simple replace on the string:

textBox.Text = textBox.Text.Replace("Yes", "NO")

Changing the color is a different matter. I assume you want to change only the replaced text to red, which won't work unless you're using a rich text box. If it's just a regular text box then you're limited to a global foreground color change. But that can be done by changing the ForeColor property:

textBox.ForeColor = Color.Red

For a rich text box it's a bit more complicated, but you can search for substrings with that control, select them, and then set the color for the selection to red. See the documentation for details.

Sir deceptikon how about if I use rich text box what is the code for changing the color?

how about this

if RichTextBox1.Text = "yes" Then
    RichTextBox1.Select(RichTextBox1.TextLength - 3, 3)
    RichTextBox1.SelectionColor = Color.Red
    RichTextBox1.SelectedText = "no"
End if

Sir deceptikon how about if I use rich text box what is the code for changing the color?

I especially like how you read the documentation I linked you to that gave details on how to do exactly that before asking. Oh wait, you didn't. :rolleyes:

Edited 3 Years Ago by deceptikon

This question has already been answered. Start a new discussion instead.