html color coding

This is really complexe, and i can understand if noone can help me, but i will still ask. i am trying to get my richtextbox to change certion text to a certion color. I.E. when they type then it will change that block of text to a color. all this to happen with the push of a button. i know who change the entire richtextbox color, but just part of it? that is what is confuseing me. so if you guys could tell me how to get therichtextbox to pick out a certion word () and that would be great. thanks.

Comments

  • Hi,
    What exactly do you want to do? You want the user to write in the color of the font they want the font to be and then the font should change to that color??? If so i think i can help. You should make a textbox and then name it. Then open the Windows generated code in the code window. Then copy the part where it says the name of the richtextbox.font to the button click that you want the user to click after they typed in the color. Then declare a variable, say x. Then do:

    txtbox1.text = x

    Then in the stuff you copied , find the font.color part and then just type in x instead of a color. If that doesn't work, then i have no clue, whatsoever.

    HTH
    Dhruv(BattleGuard)



    : This is really complexe, and i can understand if noone can help me, but i will still ask. i am trying to get my richtextbox to change certion text to a certion color. I.E. when they type then it will change that block of text to a color. all this to happen with the push of a button. i know who change the entire richtextbox color, but just part of it? that is what is confuseing me. so if you guys could tell me how to get therichtextbox to pick out a certion word () and that would be great. thanks.
    :

  • Hi,

    Say for example you have the following sentence in your rich text box..

    This page is written in . This page is written in .

    Do you want to colour each instance of "" red while leaving the rest black?
    If so here's a possibility...

    Private Sub SetColour()
    Dim nPos As Int16
    Dim s As String
    Dim htmlColor As Color = Color.Red
    Dim sHtml As String = ""

    s = rtb.Text 'Assign text to string variable to modify
    rtb.SelectAll() 'Select all richbox text
    rtb.SelectionColor = Color.Black 'default to black
    Do While s.IndexOf(sHtml) > -1 'while "" occurs in s
    nPos = s.IndexOf(sHtml) + (Len(rtb.Text) - Len(s))
    rtb.Select(nPos, Len(sHtml)) 'select instance of ""
    rtb.SelectionColor = htmlColor 'colour it accordingly
    s = rtb.Text.Substring(nPos + Len(sHtml))
    Loop
    rtb.Select(rtb.TextLength + 1, 1) 'position at end of text
    rtb.SelectionColor = Color.Black 'next text typed will be black
    End Sub

    Hope this helps,

    Chris


    : This is really complexe, and i can understand if noone can help me, but i will still ask. i am trying to get my richtextbox to change certion text to a certion color. I.E. when they type then it will change that block of text to a color. all this to happen with the push of a button. i know who change the entire richtextbox color, but just part of it? that is what is confuseing me. so if you guys could tell me how to get therichtextbox to pick out a certion word () and that would be great. thanks.
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories