how to color one word of text in a FCTB (Fast Color Text Box)

1.9k Views Asked by At

I can create a Fast Color Text Box in C# and add text to it easily:

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.";

I don't understand how to change just one word of that text to a different color.

I don't want to identify the word via syntax, my application is more like a word processor where the user wants color to emphasize a word.

For instance, how can I change the word "some" in the above code segment to appear in green instead of black?

Thanks

1

There are 1 best solutions below

0
On BEST ANSWER

I finally found the member function that I was looking for.

Here is how to do it.

  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);