This is a migrated thread and some comments may be shown as answers.

Remove Hyperlinks when Executing PasteCommand?

1 Answer 115 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Siamak
Top achievements
Rank 1
Siamak asked on 26 Oct 2012, 03:33 PM
I try to do this by using this Thread's Posts but when I Paste Some text contain hyperlink in my RadRichTextBox , It shows the hyperlinks as usual way and doesn't remove Its styles and etc.
I Want remove any styles, Images, Tables, Bullets, etc of document's content like when paste Clipboard in TextBox.

1 Answer, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 29 Oct 2012, 03:37 PM
Hello Siamak,

If I understand correctly, you wish to convert the rich text that has been copied and paste it as plain text.

If this is the case, you can do so using the TxtFormatProvider which is built to import/export plain text.
void radRichTextBox_CommandExecuting(object sender, Telerik.Windows.Documents.RichTextBoxCommands.CommandExecutingEventArgs e)
{
    if (e.Command is PasteCommand)
    {
        DocumentFragment fragment = ClipboardEx.GetDocument();
        if (fragment != null)
        {
            TxtFormatProvider provider=new TxtFormatProvider();
            string plainText = provider.Export(fragment.ToDocument());
            this.radRichTextBox.InsertFragment(new DocumentFragment(provider.Import(plainText)));
            e.Cancel = true;
        }
    }
}
This will strip the text in the clipboard of all formatting and will insert it at the caret position.

I hope this helps.

 
All the best,
Petya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
RichTextBox
Asked by
Siamak
Top achievements
Rank 1
Answers by
Petya
Telerik team
Share this question
or