C# RichTextBox 彩色文本 [英] C# RichTextBox colored text
问题描述
我有一个 RichTextBox,我想在其中添加彩色文本.有没有标签选项?我想要这样的[color:red]nick[/color] 一些消息
.因为我需要将其另存为文本,并且我希望重新加载时也有彩色文本.
I've a RichTextBox and I want color text in it. Is there any tag option? I'd like something like this [color:red]nick[/color] some message
. Because I need to save it as text and I want on reload have also colored text.
我可以在不编写自己的方法的情况下做这样的事情吗?
Can I do something like this without writing own method?
推荐答案
您可以使用 SelectionColor
如果要将 rtf 保存为纯文本,则必须查看 rtf 格式.示例:
And if you want to save your rtf as plain text, then you will have to look at rtf format. Example:
{\rtf1\ansi\deff0 {\colortbl;\red0\green0\blue0;\red255\green0\blue0;}此行为默认颜色\line \cf2 此行为红色\line \cf1此行为默认颜色 }
{\rtf1\ansi\deff0 {\colortbl;\red0\green0\blue0;\red255\green0\blue0;} This line is the default color\line \cf2 This line is red\line \cf1 This line is the default color }
从这个例子中 - 首先你必须以下列格式声明颜色表 \colortbl
:
From this example - first of all you have to declare color table \colortbl
in fololowing format:
{\colortbl; color1; color2; ... ; colorN;}
然后在文本中,您必须用 {\cfN YOUR_TEXT}
将文本括起来,其中 N 是表中的颜色数;你不能指定块 {} 的边界,那么 \cfN 之后的一切都会是一种颜色.
And then in the text you will have to enclose text with {\cfN YOUR_TEXT}
where N is a number of color from table; you can not specify the boundaries of the block {}, then everything after \ cfN will be one color.
这篇关于C# RichTextBox 彩色文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!