开发者

How can I color text in a Rich Textbox in C#? [duplicate]

开发者 https://www.devze.com 2023-03-13 15:56 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: C# How can I set the color of text in a richtextbox?
This question already has answers here: Closed 11 years ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号