Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

Change color of certain words in RichTextBox?

$
0
0
Hello, vbforums. This is my first post :P

Anyway, what I am wanting to do is add colors to certain words in a RichTextBox. I am reading .txt files into a RichTextBox, and I also want the user to have the option to color words as they like. It's easily done with - RichTextBox1.SelectionColor = Color.Red - but since the colors do not save to the .txt file, I am wanting to make "tags" in the .txt, such as - "[cr]"+"[/cr]" (which will stand for "colorred", and it should change the color of the text inside of these tags and hide the tags, but I just want to get the tags to work first). I'm not sure if "[cr]" + "[/cr]" is how it would be done, though. I was trying to keep the code simple, however, it's proving to be quite a pain. This is what I have, but it doesn't work:

(This is on Form1_Load)

Code:

If RichTextBox3.Find("[cr]" + "[/cr]") Then
            RichTextBox3.SelectedText = "[cr]" + "[/cr]"
            RichTextBox3.SelectionColor = Color.Red
            RichTextBox3.Refresh()
        Else
            MsgBox("Failed to change color")
        End If

I first did this, just to see if Find was doing anything, and it does:
Code:

If RichTextBox3.Find("[cr]") Then
          RichTextBox3.ForeColor = Color.Red
        End If

Any help would be appreciated :)

I'm using VS 2012

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>