C# 如何在富文本框中设置文本的颜色? [英] C# How can I set the color of text in a richtextbox?

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

问题描述

我在应用中有一个富文本框,我希望关键字采用另一种颜色,我该怎么做?

I have a richtextbox in an app and I'd like key words to be in another color, how can I do this?

谢谢玉

推荐答案

你可以使用:

richTextBox1.SelectionColor = Color.Yellow;
richTextBox1.SelectionBackColor = Color.Blue;

选择一个文本集:

richTextBox1.SelectionStart = text_position_in_editor (caret position)

richTextBox1.SelectionLength = text_length

然后设置 SelectionColor ...(查看所有以 Selection... 开头的属性)

then set SelectionColor ... (see all properties starting with Selection...)

或者,您可以直接设置包含格式信息的Rtf 属性(或richTextBox1.SelectedRtf).

Or, you can set directly the Rtf property (or richTextBox1.SelectedRtf) which contains formatting info.

在写字板中输入一些文本,更改其格式,将其复制并粘贴到您的 RichTextBox 中,显示属性 Rtf 值,您应该能够更快地了解如何满足您的需求.

Type some text in WordPad, change it's formatting, copy and paste it into your RichTextBox, show the property Rtf value, you should be able to learn faster how to meet your needs.

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

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