|
-
Oct 31st, 2003, 11:56 AM
#1
Thread Starter
New Member
Change Font Color While Typing
How do I change the font color on a rich textbox while I'm typing?
http://www.lyricsserver.net
-
Oct 31st, 2003, 01:44 PM
#2
New Member
I'm not sure if this what you were asking but anyhow:
VB Code:
Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
RichTextBox1.ForeColor = Drawing.Color.Blue
End Sub
-
Oct 31st, 2003, 01:53 PM
#3
Thread Starter
New Member
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
-
Oct 31st, 2003, 02:22 PM
#4
New Member
VB Code:
Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
RichTextBox1.Find("STRING", RichTextBox1.SelectionStart - 6, RichTextBoxFinds.None)
RichTextBox1.SelectionColor = Drawing.Color.Red
RichTextBox1.Select(RichTextBox1.Text.Length, 0)
RichTextBox1.SelectionColor = Drawing.Color.Black
End Sub
-
Nov 1st, 2003, 05:23 AM
#5
Thread Starter
New Member
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
-
Nov 1st, 2003, 10:08 AM
#6
yay gay
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/
-
Nov 1st, 2003, 10:46 AM
#7
Thread Starter
New Member
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
-
Nov 1st, 2003, 11:07 AM
#8
Lively Member
Your Problem is Solved
I hope this is the code that will solve your problem.
GodLovesYou Your code was messed up.
VB Code:
Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
If InStr(richtextbox1.text, "STRING", CompareMethod.Binary) Then
RichTextBox1.Find("STRING", RichTextBox1.SelectionStart - 6, RichTextBoxFinds.None)
RichTextBox1.SelectionColor = Drawing.Color.Red
End If
RichTextBox1.Select(RichTextBox1.Text.Length, 0)
RichTextBox1.SelectionColor = Drawing.Color.Black
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."
-
Nov 1st, 2003, 03:05 PM
#9
yay gay
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:
Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
If InStr(richtextbox1.text, "STRING", CompareMethod.Binary) Then
RichTextBox1.Find("STRING", RichTextBox1.SelectionStart - 6, RichTextBoxFinds.None)
RichTextBox1.SelectionColor = Drawing.Color.Red
End If
RichTextBox1.Select(RichTextBox1.Text.Length, 0)
RichTextBox1.SelectionColor = Drawing.Color.Black
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:
Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
dim pos as integer = richtextbox1.position 'or whatever property it has to get the position
If InStr(richtextbox1.text, "STRING", CompareMethod.Binary) Then
RichTextBox1.Find("STRING", RichTextBox1.SelectionStart - 6, RichTextBoxFinds.None)
RichTextBox1.SelectionColor = Drawing.Color.Red
End If
RichTextBox1.Select(pos, 0)
RichTextBox1.SelectionColor = Drawing.Color.Black
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|