Paste plain text when copying\pasting in same RadRichTextBox

2 posts, 1 answers
  1. Chris
    Chris avatar
    9 posts
    Member since:
    Apr 2014

    Posted 02 Jan 2015 Link to this post

    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?
  2. Answer
    Boby
    Admin
    Boby avatar
    595 posts

    Posted 06 Jan 2015 Link to this post

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top