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

How to override cut,copy,paste event of rad richtextbox

5 Answers 234 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Amit
Top achievements
Rank 1
Amit asked on 18 Oct 2011, 04:29 PM
Hi,

I want to override cut,copy,paste event of richetextbox.
Is it any way to implement it?

Please share.

Regards,
Amit Nadhe

5 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 21 Oct 2011, 10:36 AM
Hello Amit,

You cannot override the default clipboard commands.
However, you can disable their execution and wire in your implementations of the commands.
You can find an example of how to create a custom command and wire it with RadRichTextBoxRibbonUI in this forum thread. You can also build a custom ContextMenu that executes your commands. For more information on how to do that, you can refer to this article.
Lastly, the clipboard commands can be executed using the keyboard shortcuts (Ctrl + C, Ctrl + V, Ctrl + X).
There is a list of the keyboard shortcuts and the commands they trigger, as well as possible customization options in this article
I hope this helps.

Regards,
Iva Toteva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Robert
Top achievements
Rank 1
answered on 30 Aug 2012, 04:10 PM
Hi,

I have a similar issue. I don't want to override the cut / copy / paste commands, rather I want to trigger another event when the cut command is executed so that I can run some check methods.

Is there a way to raise an event such as Preview Cut?
0
Iva Toteva
Telerik team
answered on 31 Aug 2012, 03:57 PM
Hi Rob,

There is an event CommandExecuting, which is fired when any command is triggered. You can check if the command that has caused the triggering of the event is Cut and interrupt its execution if some criteria are matched:

private void editor_CommandExecuting(object sender, Telerik.Windows.Documents.RichTextBoxCommands.CommandExecutingEventArgs e)
{
    if (e.Command is CutCommand && shouldInterrupt)
    {
        e.Cancel = true;
    }
}

For simplicity, I have used a hypothetical shouldInterrupt boolean field. You can either use a field or perform some checks in the handler of the event.

I hope this helps.

Kind regards,
Iva Toteva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Robert
Top achievements
Rank 1
answered on 31 Aug 2012, 07:43 PM
Thanks Iva, that works perfectly.

I just needed to assign the event like so:
this.editor.CommandExecuting += editor_CommandExecuting;


One last question. How do I access the clipboard data? What I want to do is loop through the clipboard data before it is pasted to check if it contains any annotations with specific property values.

I can obviously capture the event like so:
if (e.Command is PasteCommand)
{
}

Thanks again for your time and help.

All the best,

Rob
0
Nikolay Demirev
Telerik team
answered on 04 Sep 2012, 10:10 AM
Hi Rob,

You can use this code snippet to get the document fragment from the clipboard:

if (e.Command is PasteCommand)
{
    DocumentFragment fragment = ClipboardEx.GetDocument();
    if (fragment != null)
    {
        // loop through clipboard data
    }
}

DocumentFragment has mostly the same structure of a RadDocument and you can use the EnumerateChildrenOfType<YourAnnotationRangeStart>() method to get all annotation starts and check their properties.

I hope this helps.

Kind regards,
Nikolay Demirev
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
RichTextBox
Asked by
Amit
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Robert
Top achievements
Rank 1
Nikolay Demirev
Telerik team
Share this question
or