Results 1 to 9 of 9

Thread: Change Font Color While Typing

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2003
    Location
    Philippines
    Posts
    15

    Question Change Font Color While Typing

    How do I change the font color on a rich textbox while I'm typing?
    http://www.lyricsserver.net

  2. #2
    New Member
    Join Date
    Sep 2003
    Posts
    8
    I'm not sure if this what you were asking but anyhow:

    VB Code:
    1. Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
    2.         RichTextBox1.ForeColor = Drawing.Color.Blue
    3.     End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2003
    Location
    Philippines
    Posts
    15

    Question

    Sorry. I mean on selected keywords. I'll re-phrase it.

    How do I change the font color on selected keywords on a rich textbox while I'm typing? Keywords such as "SELECT" or "QUERY."
    http://www.lyricsserver.net

  4. #4
    New Member
    Join Date
    Sep 2003
    Posts
    8
    VB Code:
    1. Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
    2.         RichTextBox1.Find("STRING", RichTextBox1.SelectionStart - 6, RichTextBoxFinds.None)
    3.         RichTextBox1.SelectionColor = Drawing.Color.Red
    4.         RichTextBox1.Select(RichTextBox1.Text.Length, 0)
    5.         RichTextBox1.SelectionColor = Drawing.Color.Black
    6.     End Sub

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2003
    Location
    Philippines
    Posts
    15

    Question

    Thanks but the code you gave me yields a problem. When I try to change the cursor position and enter a single character, it will immediately shift my cursor to the end of the text.
    http://www.lyricsserver.net

  6. #6
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    are you trying to do a IDE like textbox? that will color words? that might give you a lot of trouble, the best way to do it maybe would be superclass the base textbox control and not the richtextbox control as it is slow for all this kind of operations
    \m/\m/

  7. #7

    Thread Starter
    New Member
    Join Date
    Sep 2003
    Location
    Philippines
    Posts
    15

    Arrow

    Originally posted by PT Exorcist
    are you trying to do a IDE like textbox? that will color words? that might give you a lot of trouble, the best way to do it maybe would be superclass the base textbox control and not the richtextbox control as it is slow for all this kind of operations
    Yes! But I don't know how to do what you just said.
    http://www.lyricsserver.net

  8. #8
    Lively Member
    Join Date
    Aug 2003
    Location
    When?!?!
    Posts
    108

    Your Problem is Solved

    I hope this is the code that will solve your problem.

    GodLovesYou Your code was messed up.

    VB Code:
    1. Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
    2.         If InStr(richtextbox1.text, "STRING", CompareMethod.Binary) Then
    3.             RichTextBox1.Find("STRING", RichTextBox1.SelectionStart - 6, RichTextBoxFinds.None)
    4.             RichTextBox1.SelectionColor = Drawing.Color.Red
    5.         End If
    6.             RichTextBox1.Select(RichTextBox1.Text.Length, 0)
    7.             RichTextBox1.SelectionColor = Drawing.Color.Black
    8.     End Sub

    Remember, when comparing by binary, all selections will be case-sensative. If you want me to create the complete code for you, just send me a private message.
    Last edited by Danny J; Nov 1st, 2003 at 11:30 AM.
    DannyJoumaa
    Advanced VB6 Programmer
    Intermediate-Advanced VB .NET Programmer
    Intermediate C# Programmer
    Intermediate Win32 Developer
    Beginner Mac OS X Developer
    Contact: [email protected]

    Favorite Sayings:
    "Every time you open your mouth, you prove your an idiot."
    "God is a programmer. Satan is a bug. Life is debugging."

  9. #9
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729

    Re: Your Problem is Solved

    Originally posted by Danny J
    I hope this is the code that will solve your problem.

    GodLovesYou Your code was messed up.

    VB Code:
    1. Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
    2.         If InStr(richtextbox1.text, "STRING", CompareMethod.Binary) Then
    3.             RichTextBox1.Find("STRING", RichTextBox1.SelectionStart - 6, RichTextBoxFinds.None)
    4.             RichTextBox1.SelectionColor = Drawing.Color.Red
    5.         End If
    6.             RichTextBox1.Select(RichTextBox1.Text.Length, 0)
    7.             RichTextBox1.SelectionColor = Drawing.Color.Black
    8.     End Sub

    Remember, when comparing by binary, all selections will be case-sensative. If you want me to create the complete code for you, just send me a private message.
    i didnt try it but it doesnt look to me as it would ever work as in the end you are selecting the end of the richtextbox...if he is writing in the middle then it wont work

    change it to this:
    VB Code:
    1. Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
    2. dim pos as integer = richtextbox1.position 'or whatever property it has to get the position
    3.         If InStr(richtextbox1.text, "STRING", CompareMethod.Binary) Then
    4.             RichTextBox1.Find("STRING", RichTextBox1.SelectionStart - 6, RichTextBoxFinds.None)
    5.             RichTextBox1.SelectionColor = Drawing.Color.Red
    6.         End If
    7.             RichTextBox1.Select(pos, 0)
    8.             RichTextBox1.SelectionColor = Drawing.Color.Black
    9.     End Sub
    i dont have vs.net here so i cant test it but it would be something like this
    \m/\m/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width