I have read a number of articles about formatting text in a RichTextBox as the user types by selecting text based on a search and then setting the SelectionColour property; I don't like this as the flashy behaviour of the selection doesn't look very good.
With that in mind, I am instead using a procedure to 'build' the raw RTF text which defines the formatting required based on the text and then just sets the Rtf property of the RichTextBox.
However, what I can't understand is that, after I've created the raw RTF string, when this is passed to the Rtf property of the RichTextBox, it's getting overridden by something completely different.
This is the raw RTF string which I've created with the procedure:
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\colortbl;\red0\green0\blue0;
\red65\green105\blue225;\red255\green0\blue0;\red255\green192\blue203;
\red128\green128\blue128;\red255\green165\blue0;\red34\green139\blue34;}
{\fonttbl\n{\f0\fswiss\fcharset1252 Courier New;}\n}{\cf2select \cf5left}}
When I set the Rtf property of the RichTextBox to this string, what it actually sets it to is:
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl
{\f0\fswiss\fcharset0 Courier New;}}\r\n{\colortbl;\red65\green0\blue0;\red0\green0\blue0;}
\r\n\viewkind4\uc1\pard\cf1\f0\fs24 se\\cf5\cf2 cf1lect left\par\r\n}\r\n
What is even more confusing to me is that if I set the Rtf property of the RichTextBox in the form constructor rather than in this procedure, it does set it to the passed value exactly and I get the text formatting that I want.
What I am trying to understand is why the Rtf property is not being set to what I pass it and seems to be getting set to something completely different.