• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 696
  • Last Modified:

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.
0
H-SC
Asked:
H-SC
  • 2
1 Solution
 
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
 
Mike TomlinsonMiddle 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
 
H-SCAuthor Commented:
Idle Mind,

That worked great !
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now