更改文本字体的RichTextBox中 [英] Change font of text in richtextbox

查看:165
本文介绍了更改文本字体的RichTextBox中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的文字是在一个RichTextBox:



<预类=郎咸平的XML prettyprint-覆盖> < Parag1级别=一> ;
parag1的第一个文本。 parag1的第二个文本。
< / Parag1>
< Parag2级别=二>
parag2的第一个文本。 parag2的第二个文本。
< / Parag2>
< Parag3级别=页脚>
parag3的第一个文本。 parag3的第二个文本。
< / Parag3>
< Parag4级别=三>
parag4的第一个文本。 parag4的第二个文本。
< / Parag4>



我想改变颜色的字体和放大器;文本的文本颜色:



1为标签 - >字体名=宋体,大小= 10的color = red



例如:< Parag1级别=一个> < / Parag1>



2 - 对于标签之间的文本标签的水平不页脚 - >字体名=宋体,大小= 12,颜色=黑色



例如: parag1的第一个文本。 parag1的第二个文本。 parag4的第一个文本。 。parag4的第二个文本



3对于标签之间的文本标签的水平页脚 - >字体名称= Microsoft无衬线,大小= 8 ,颜色=蓝色



例如: parag3的第一个文本。 parag3的第二个文本。



我怎么能做到这一点在C#?(更改所有文本的字体一次!)


解决方案

您需要选择部分文本,并使用 selectionColor设置 SelectionFont 属性。
一切都在这里解释



希望这有助于



为您的其他问题,如果你的意思是如何改变字体和文本的颜色插入的程序运行时,试试这个。

 私人无效someTextBox_KeyPress(对象发件人,KeyPressEventArgs E)
{
this.someTextBox.SelectionColor = Color.Blue;
//同去的字体和其他属性
}



我不吨有时间来测试它,所以我不知道它会如何与你之前设置的其他颜色行事。


My text is in a 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>

I want change color font & text color of text :

1- For tags -> font name = Tahoma , size= 10,color=red

Example : <Parag1 Level="One"> Or </Parag1>

2- For Text between tags that tag's level is not Footer -> font name = Arial , size= 12,color=black

Example : First text of parag1. Second text of parag1. Or First text of parag4. Second text of parag4.

3- For Text between tags that tag's level is Footer -> font name = Microsoft Sans Serif, size= 8,color=blue

Example : First text of parag3. Second text of parag3.

How can I do it in c# ?(Changes font of all text at once!)

解决方案

You would need to select parts of text and use SelectionColorand SelectionFontproperties. Everything is explained here.

Hope this helps

Now for your other question, if you mean how to change the font and color of the text inserted while the program is running, try this.

         private void someTextBox_KeyPress(object sender, KeyPressEventArgs e)
         {
           this.someTextBox.SelectionColor = Color.Blue; 
           // Same goes for font and other properties
         }

I don't have time to test it so I don't know how it will act with the other colors you previously set.

这篇关于更改文本字体的RichTextBox中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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