C# 如何在富文本框中设置文本的颜色?

编程入门 行业动态 更新时间:2024-10-27 07:31:05
本文介绍了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# 如何在富文本框中设置文本的颜色?

本文发布于:2023-06-09 04:14:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/595024.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本   框中   颜色   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!