簡體   English   中英

在richtextbox中更改文本字體

[英]Change font of text in richtextbox

我的文字位於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>

我想要更改文本的顏色字體和文本顏色:

1-對於標簽 - >字體名稱= Tahoma,尺寸= 10,顏色=紅色

示例: <Parag1 Level="One"></Parag1>

2-對於標簽之間的文本,標簽的級別不是頁腳 - >字體名稱= Arial,大小= 12,顏色=黑色

示例: First text of parag1. Second text of parag1. First text of parag1. Second text of parag1. 或者First text of parag4. Second text of parag4. First text of parag4. Second text of parag4.

3-對於標簽之間的文本標簽的級別是頁腳 - >字體名稱= Microsoft Sans Serif,size = 8,color = blue

示例: First text of parag3. Second text of parag3. First text of parag3. Second text of parag3.

如何在c#中執行此操作?(一次更改所有文本的字體!)

您需要選擇部分文本並使用SelectionColorSelectionFont屬性。 這里解釋一切。

希望這可以幫助

現在,對於您的其他問題,如果您的意思是如何更改程序運行時插入的文本的字體和顏色,請嘗試此操作。

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

我沒有時間測試它,所以我不知道它將如何與你之前設置的其他顏色一起使用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM