RichTextBox.SelectionColor not taking effect

  • Thread starter Thread starter buht
  • Start date Start date
B

buht

Hello.

Ive got a form with one richtextbox object called outputBox. When I
click a button on the form that calls some other things to happen one
of those things is setting the outputBox.SelectionColor to a new color
other than the default forecolor of the outputBox.

When I do this, from reading MSDN's explanation, I am under the
assumption that new text entered after this point will be of that
color until I change it to something else or back to the forecolor
default. This does not occur. the text remains the same color as the
objects forecolor value. I've removed the forecolor values and still
have had no luck. Below is an example of what I'm doing.

this.outputBox.SelectionColor = Color.Yellow;
this.outputBox.Text += "blah blah blah";
this.outputBox.SelectionColor = Color.White;

The blah blah blah text remains white and for the life of me I cant
figure it out hehe. Any ideas on what I'm doing wrong?

-Buht
 
buht said:
this.outputBox.Text += "blah blah blah";

Use:

this.outputBox.SelectedText = "blah blah blah";

You may want to set SelectionStart first; i.e.:

this.outputBox.SelectionStart = this.outputBox.TextLength;
 
Back
Top