Paste as plain text

2 posts, 1 answers
  1. Euan
    Euan avatar
    3 posts
    Member since:
    Oct 2010

    Posted 23 Oct 2013 Link to this post

    Hi,

    I'm trying to intercept the paste event when the user has pressed control -v, to paste the clipboard contents as plain text.
    But I can't work out where to start ?

    Thanks
    Euan
  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    1411 posts

    Posted 28 Oct 2013 Link to this post

    Hi Euan,

    Thank you for writing.

    To intercept and change the default behaviour of the Ctrl+V key combination you can use the following custom InputBehavior class: 
    class MyInputBeaviour : InputBehavior
    {
        public MyInputBeaviour(DocumentView view) : base(view)
        {
        }
     
        protected override bool ProcessKeyDownCore(KeyEventArgs e)
        {
            if (e.Control && e.KeyCode == Keys.V)
            {
                 
                RadDocument document = this.DocumentView.Document;
                document.Insert((string)Clipboard.GetData("Text"), new StyleDefinition());
                e.SuppressKeyPress = true;
                return false;
            }
            else
            {
                return base.ProcessKeyDownCore(e);
            }
        }
    }

    Then you just need to change the default behaviour with the new one:
    radRichTextBox1.RichTextBoxElement.ViewElement.DocumentView.InputBehavior = new MyInputBeaviour(doc.DocumentView);

    I hope this will be useful. Should you have further questions, I would be glad to help.

    Regards,
    Dimitar
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top