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

Paste as plain text

1 Answer 18 Views
RichTextBox (obsolete as of Q3 2014 SP1)
This is a migrated thread and some comments may be shown as answers.
Euan
Top achievements
Rank 1
Euan asked on 23 Oct 2013, 09:02 AM
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

1 Answer, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 28 Oct 2013, 07:17 AM
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 >>
Tags
RichTextBox (obsolete as of Q3 2014 SP1)
Asked by
Euan
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or