如何在C#中的RTF文本框中为文本着色? [英] How can I color text in a Rich Textbox in C#?

查看:78
本文介绍了如何在C#中的RTF文本框中为文本着色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

在Visual C#.NET中,我想在将其键入到富文本框中时更改特定文本的颜色。

In Visual C#.NET, I want to change the color of specific text when it is typed in to a rich text box.

例如,我可能想为世界 hi着色,因此,当用户在富文本框中键入内容时,如果他们键入 hi,它将更改颜色,并且单词 hi也会更改富文本框中所有其他文本的颜色将与其他颜色不同。

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 rich textbox?

推荐答案

在您的TextChanged事件处理程序中

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);

这篇关于如何在C#中的RTF文本框中为文本着色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆