|
-
Jun 1st, 2006, 04:02 PM
#1
Thread Starter
Addicted Member
[2005] How To Change the Color of a Typed Word in a RTB
I am making a coding assistant program, and I want to make it so that after a user presses the space bar, if the last word typed is one that the program recognizes, it will turn it to the color specified.
Basically, I want to do syntax highlighting. If there is any easier way than this please tell me, or else post some code.
-
Jun 1st, 2006, 04:13 PM
#2
Re: [2005] How To Change the Color of a Typed Word in a RTB
I don't know how, but I did a search and found a sample for something similar. Perhaps this can guide you.
http://pietschsoft.com/Blog/Post.aspx?PostID=491
-
Jun 1st, 2006, 04:33 PM
#3
Thread Starter
Addicted Member
Re: [2005] How To Change the Color of a Typed Word in a RTB
Great, but, How do I use it?
-
Jun 1st, 2006, 04:36 PM
#4
Re: [2005] How To Change the Color of a Typed Word in a RTB
That person there is creating an inherited control. The control has been inherited from the existing RTB control, he's just adding his own routines to it and overriding a few existing routines.
You could start by... copy-pasting that code into a windows control project class library, compiling it, and then adding that control to another project ( a test project). Then start hacking away at the code.
-
Jun 1st, 2006, 04:47 PM
#5
Re: [2005] How To Change the Color of a Typed Word in a RTB
 Originally Posted by Seraphino
I am making a coding assistant program, and I want to make it so that after a user presses the space bar, if the last word typed is one that the program recognizes, it will turn it to the color specified.
Basically, I want to do syntax highlighting. If there is any easier way than this please tell me, or else post some code.
Hi,
I think you can use the ColorDialog for that, here's an exa^mple with a RichTextBox and a Button.
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If ColorDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
rtxtEditor.ForeColor = ColorDialog1.Color
End If
End Sub
Hope it helps,
sparrow1
-
Jun 1st, 2006, 05:37 PM
#6
Thread Starter
Addicted Member
Re: [2005] How To Change the Color of a Typed Word in a RTB
Nope, this isn't what I wanted, but thanks for the tip!
-
Jun 4th, 2006, 03:22 PM
#7
Addicted Member
Re: [2005] How To Change the Color of a Typed Word in a RTB
Try
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If ColorDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
rtxtEditor.SelectionColor = ColorDialog1.Color
End If
End Sub
-
Jun 4th, 2006, 03:29 PM
#8
Re: [2005] How To Change the Color of a Typed Word in a RTB
Ken B is right, there is no other way to change the color of only some letters in a generic richtextbox unless you select them first and then use "richtextbox.SelectionColor = Color.some color"
(I'd be gladly wrong, since the whole select business is kind of fishy, one unintented click from the user can wreak havoc in your formatting logic)
-
Jun 4th, 2006, 03:52 PM
#9
Re: [2005] How To Change the Color of a Typed Word in a RTB
(I'd be gladly wrong, since the whole select business is kind of fishy, one unintented click from the user can wreak havoc in your formatting logic)
The click won’t change the selection property of the Rich Tex Box. For example the “SelectionText” of the RichTextBox would always be the last word in the control unless it is changed manually.
Last edited by VBDT; Jun 4th, 2006 at 03:55 PM.
-
Jun 4th, 2006, 04:05 PM
#10
Re: [2005] How To Change the Color of a Typed Word in a RTB
 Originally Posted by VBDT
The click won’t change the selection property of the Rich Tex Box. For example the “SelectionText” of the RichTextBox would always be the last word in the control unless it is changed manually.
I just checked it, RichTextBox1.Select(0, 8) -> user clicks inside -> RichTextBox1.SelectionColor = Color.Red doesn't change the color of the previous selection to red.
-
Jun 4th, 2006, 04:34 PM
#11
Re: [2005] How To Change the Color of a Typed Word in a RTB
Yes you are right! On the click event “SelectionText’s” index is set to 0. Never mind my previous comment.
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
|