0

我可以在 C# 中创建一个快速彩色文本框并轻松地向其中添加文本:

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”更改为绿色而不是黑色?

谢谢

4

1 回答 1

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);
于 2016-09-16T00:39:52.363 回答