更改文本字体的RichTextBox中

编程入门 行业动态 更新时间:2024-10-27 07:25:51
本文介绍了更改文本字体的RichTextBox中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的文字是在一个RichTextBox:

< 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中

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

发布评论

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

>www.elefans.com

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