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

Paste plain text when copying\pasting in same RadRichTextBox

1 Answer 519 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 02 Jan 2015, 08:56 PM
I am trying to override the default clipboard behavior to only support pasting plain text using the following code:

ClipboardEx.ClipboardHandlers.Clear();
var clipboardHandler = new ClipboardHandler();
clipboardHandler.ClipboardDataFormat = DataFormats.Text;
clipboardHandler.DocumentFormatProvider = new TxtFormatProvider();
ClipboardEx.ClipboardHandlers.Add(clipboardHandler);

This seems to work appropriately when pasting from an application such as MS Word. However, if I copy from a RadRichTextBox and then paste into the same RadRichTextBox, the formatting is preserved. How can I also paste plain text when copying from the same RadRichTextBox I am pasting into?

1 Answer, 1 is accepted

Sort by
0
Accepted
Boby
Telerik team
answered on 06 Jan 2015, 01:41 PM
Hi Chris,
Copy/pasting from RadRichTextBox to RadRichTextBox cannot be controlled on Clipboard handler level.

You can instead change the default pasting behavior:
{
    //...
    radRichTextBox.CommandExecuting += radRichTextBox_CommandExecuting;
}
 
void radRichTextBox_CommandExecuting(object sender, CommandExecutingEventArgs e)
{
    if (e.Command is PasteCommand)
    {
        e.Cancel = true;
        this.radRichTextBox.Insert(Clipboard.GetText());
    }
}

Using this approach, you won't even need to change the registered clipboard handlers.

Regards,
Boby
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
RichTextBox
Asked by
Chris
Top achievements
Rank 1
Answers by
Boby
Telerik team
Share this question
or