I am using Visual Studio 10, .NET Framework 4 and was creating a Rich Text Box Control for Text Input. I am formatting text ONLY by writing the
*RichTextBox*.SelectionFont = new Font(currentFontFamily, currentFontSize, currentFontStyle);
Method.
When I am now accessing the Rtf formatted String via the RichTextBox.Rtf property, it works, but ONLY contains the first formatting.
For example:
Hello World
results in:
{\rtf1\ansi\ansicpg1252\deff0\deflang1031{\fonttbl{\f0\fnil\fcharset0 Verdana;}}
{\colortbl ;\red0\green0\blue0;}
\viewkind4\uc1\pard\cf1\b\f0\fs18 Hello World\par
}
which actually is Hello World
This is the same for everything. Fonts, Sizes, Colors, Formatting and so on. Can anyone help??
This is propably because the properties SelectionStart and SelectionLength are not valid. If you explicit limit the selection via those properties the RTF-output will be as expected:
becomes
Edit:
As the asker mentioned below the real cause of the problem was a call to TrimEnd():
As soon as he removed it everything worked as expected.