2016-09-15 76 views
0

我可以創建在C#中的快速彩色文本框和文本添加到很容易:如何着色的FCTB(快速彩色文本框)文本的一個字

FastColoredTextBox tb = new FastColoredTextBox(); 
this.Controls.Add(tb); 
tb.Location = new Point(10, 10); 
tb.Visible = true; 
tb.Text = "This is some text to display in the FCTB."; 

我不知道如何將該文本的一個詞改爲不同的顏色。

我不想通過語法來識別單詞,我的應用程序更像是一個文字處理器,用戶希望用顏色強調單詞。

例如,如何將上述代碼段中的單詞「some」更改爲綠色而不是黑色?

謝謝

回答

0

我終於找到了我正在尋找的成員函數。

以下是如何做到這一點。

FastColoredTextBox tb = new FastColoredTextBox(); 
    this.Controls.Add(tb); 
    tb.Location = new Point(0, 0); 
    tb.Visible = true; 
    tb.Text = "This is some text to display in the FCTB."; 
    // define a new Style... specifically a TextStyle 
    Style greenstyle = new TextStyle(Brushes.Green, Brushes.White, FontStyle.Bold); 
    // select the range of characters to modify 
    Range rng = new Range(tb, 8, 0, 12, 0); 
    // change the display to green 
    rng.SetStyle(greenstyle);