Removing Text Coloration In RichTextBox

KeysCoder

Member
Joined
Apr 10, 2006
Messages
18
Location
Florida Keys
Programming Experience
3-5
The rich text box control uses the rtf code 'cf0' to denote default text color. It builds a color table to define other colors which are used in the rtf document in the order in which they appear. If the first colored word is red for instance, the rtf code 'cf1' is used to define red.

Is there a way for me to remove the red coloration in code rather than assigning it a new color? I know I can simply assign it the default color like this:

RichTextBox1.SelectionColor = Color.Black

but the control then assigns a new color to the rtf color table: black=cf2 rather than recognizing that this is the same color as 'cf0'.

I'd rather it not do this because I'm building an application which needs to read the color of words in an rtf document. I can work around the issue but I'm suprised there doesn't seem to be a way to avoid it.
 
KeysCoder said:
there doesn't seem to be a way to avoid it.
I agree, but this should not be a big problem, it is only the default/black that gets two cfs in table. If you are in a position to, you can reset the full text to black ("cf1") and cf0 is never used.

What I see when debugging this, is that cf0 is not declared a specific color, but it returns black if you query some text color. I have also seen some other strange behaviour, when I wrote the color table manually (to try and force default-black-cf0=cf1) and then loaded it into a RTB, the color table was recompiled and cf codes rearranged upon load.
 
Yeah, it's not hard to work around - just a little sloppy. I'm suprised there isn't something like a RichTextBox.ClearRTF method to avoid having to specify the default color. It seems like such an obvious capability you would want to build into the control. I was thinking I must be missing it somehow. I guess not.
 
Back
Top