Click here to Skip to main content
16,020,626 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this code for a rich text box and i have tried this but all the content of the text box changes color not only the selected text.

Private Sub BtnColourfont_Click(sender As Object, e As EventArgs) Handles BtnColourfont.Click

    Dim simpleSound As New SoundPlayer("c:\Windows\Media\clickPolly.wav")
    simpleSound.Play()
    ColorDialog1.Color = TextBox1.ForeColor

    If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then

    End If
    RichTextBox1.ForeColor = ColorDialog1.Color
    setcolor = SelectedText
    If RichTextBox1.SelectionLength > 0 Then

    End If
    Clipboard.SetText(RichTextBox1.SelectedText)
End Sub


What I have tried:

Private Sub BtnColourfont_Click(sender As Object, e As EventArgs) Handles BtnColourfont.Click

    Dim simpleSound As New SoundPlayer("c:\Windows\Media\clickPolly.wav")
    simpleSound.Play()
    ColorDialog1.Color = TextBox1.ForeColor

    If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then

    End If
    RichTextBox1.ForeColor = ColorDialog1.Color
    setcolor = SelectedText
    If RichTextBox1.SelectionLength > 0 Then

    End If
    Clipboard.SetText(RichTextBox1.SelectedText)
End Sub
Posted
Updated 31-May-23 10:23am

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900