How can I color text in a Rich Textbox in C#? [duplicate]
Possible Duplicate:
C# How can I set the color of text in a richtextbox?
In Visual C#.NET, I want to change the color of specific text when it is typed in to a rich text box.
For example, I might want to color the world "hi", so when the user is typing in the rich text box, if they type "hi" it would change colors and the word "hi" would be a different color from all the other text in the rich text box.
How would I do that? Is there a better way to do that, not in a ric开发者_开发技巧h textbox?
in your TextChanged Event handler
txtRichTextBox.Select(txtRichTextBox.Text.IndexOf("hi"), "hi".Length);
txtRichTextBox.SelectionColor = YourColor;
txtRichTextBox.SelectionFont = new Font("Times New Roman",FontStyle.Bold);
I remember doing something like this in Flex. We had to extend the richtextbox control, and make our own custom control, that would change the text color depending on what was being entered. We used data change events to achieve this. But my gut guess is you'll have to create a custom control to do this.
精彩评论