This project has moved. For the latest updates, please go here.

Strip formatting from RTF on RichTextBox paste?

Apr 9, 2014 at 8:48 AM
Edited Apr 9, 2014 at 8:49 AM
Hi all.

I have a RichTextBox formatted to RTF. I need to lock down the text formatting of this RichTextBox to not allow any coloured font, italics etc. to be pasted in. I have a paste command and initially acheived this by calling the
method which obviously returned a text string devoid of formatting. The problem with this method is that if I try to paste in Bullets for example, the text cannot render them.

I then tried to call
This returns RTF into my RichTextBox along with bullets etc. but also carries over the font colour, size etc. that I wanted to strip out. Is there any way to bring in the Rtf string and strip formatting back? I thought about iterating over the Rtf string but the Rtf is quite complex!

Here's my Paste command code:
  private void FormatPastedTextCommandAction()
            string ClipboardText = string.Empty;

            ClipboardText = Clipboard.GetText(TextDataFormat.Rtf);

            PastedText += ClipboardText;