在富文本框文本之间插入段落并更改添加段落的字体和颜色 [英] Insert paragraph between text of richtextbox and change font and color of added paragraph

查看:72
本文介绍了在富文本框文本之间插入段落并更改添加段落的字体和颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的文本在 Richtextbox 中:

my text is in richtextbox :

<Parag1 Level="One">
First text of parag1. Second text of parag1.
</Parag1>
<Parag2 Level="Two">
First text of parag2. Second text of parag2.
</Parag2>
<Parag3 Level="Footer">
First text of parag3. Second text of parag3.
</Parag3>
<Parag4 Level="Three">
First text of parag4. Second text of parag4.
</Parag4>

所有一级、二级、三级标签的字体为Arial,Size = 9,Color = Red 示例:<Parag1 Level="One"><;/Parag4>

The font of all tags with level One, Two, Three is Arial, Size = 9, Color = Red Example : <Parag1 Level="One"> Or </Parag4>

一级、二级、三级标签之间的文本字体为 MicrosoftNewRomans,大小 = 12,颜色 = 黑色 示例:parag2 的第一个文本.parag2 的第二个文本.

The font of text between tags with level One, Two, Three is MicrosoftNewRomans, Size = 12, Color = Black Example : First text of parag2. Second text of parag2.

具有级别页脚的标签之间的文本字体为 Tahoma,大小 = 10,颜色 = 蓝色 示例:parag3 的第一个文本.parag3 的第二个文本.

The font of text between tags with level Footer is Tahoma, Size = 10, Color = Blue Example : First text of parag3. Second text of parag3.

我想在标签 3 & 之间添加这段4. 例子:

I want add this paragraph between tags 3 & 4. example :

 <NewParag5 Level="Footer">
This tags between 3 and 4.
</NewParag5>

问题:如何为段落的单独部分使用相同的字体和颜色.这意味着无需更改其他文本的字体和颜色,我可以将段落插入到 Richtextbox,然后将标签的字体或颜色更改为红色,将文本更改为蓝色.

Question : How can I do it with same font and color for seperate part of paragraph. this mean without change font and color of my other text, I can insert paragraph to richtextbox and then for tags change font or color to red, for text change to blue.

请帮助我使用 c# 和 winformsrichtextbox.

Please help me for c# and winforms richtextbox.

谢谢.

问题2:如何在文本之间添加一个段落,段落部分的字体和颜色设置为标签字体样式&文本保存前样式(字体和颜色).

Question 2 : How to add a paragraph between text, that font and color of parts of paragraph are set to tag font style & text save ago style(font & color).

推荐答案

我会尝试这种方法:单选按钮.

如果您将其中的一些添加到您的解决方案中,您可以检查输入的文本是否是标签、段落等.

If you add a few of them to your solution, you can check if the text entered is a tag, a paragraph etc..

例如

       if(tagRadioButton.Checked)
       {
          //Colors , Fonts Selection logic.
       }

如果您不想使用任何单选按钮,则可以在估算的字符串中搜索关键字并根据估算的内容更改颜色和字体.我相信你可以找到一个很好的教程,但因为我不太擅长字符串操作.

If you don't want to use any radio buttons than you could search the imputed string for keywords and change the colors and fonts depending on what is being imputed. I'm sure you can find a good tutorial on that but because i'm not really good with string manipulation.

希望这会有所帮助.

这篇关于在富文本框文本之间插入段落并更改添加段落的字体和颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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