Change font color in richtextbox only for selected string

I have a richtextbox on a form with a button that brings up a colordialog.  Currently if I use this method when I choose a color it changes everything in the richtextbox to that particular color.
here is what I would like ...
I would like to be able to highlight or select text and change the color only for the selected string.

Thanks in advance.
LVL 1
H-SCAsked:
Who is Participating?
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
Right...something like:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            RichTextBox1.SelectionColor = ColorDialog1.Color
        End If
    End Sub
0
 
Bob LearnedCommented:
Try this:

        Me.RichTextBox1.SelectionStart = 50
        Me.RichTextBox1.SelectionLength = 10
        Me.RichTextBox1.SelectionColor = Color.Red

Bob
0
 
H-SCAuthor Commented:
Bob,

Do I put this code on the button click?
0
 
H-SCAuthor Commented:
Idle Mind,

That worked great !
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.