Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

New Post: Strip formatting from RTF on RichTextBox paste?

$
0
0
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
Clipboard.GetText(); 
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
Clipboard.GetText(TextDataFormat.Rtf);
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;
                  
        }
Thanks,
Tom

Viewing all articles
Browse latest Browse all 4964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>