3 Answers, 1 is accepted
Hi Khurram,
I am not sure what is the exact requirement. Could you provide us with more information on the specific case? Is your goal to remove the images from an imported document, or you want to prevent the users from inserting images?
I am looking forward to your reply.
Regards,
Martin
Progress Telerik
Thnx Martin for your reply. Goal is to prevent users copy pasting or inserting images period. All other formatting features should stay but just no image insertion
Thnx
Hello Khurram,
In order to achieve the desired functionality, you could attach to the CommandExecuting event:
this.radRichTextBox.CommandExecuting += this.RadRichTextBox_CommandExecuting;
When handling the event in case the command is of type InsertPictureCommand the event could be canceled, the case with the PasteCommand is a little bit different. You will need to interrupt the paste command to perform some changes before adding the content inside the clipboard of the control.
For more information about ClipboardEx class, you can check the Working With the Content Inside the Clipboard help topic. Please, check the following example:
private void RadRichTextBox_CommandExecuting(object sender, CommandExecutingEventArgs e)
{
if (e.Command.GetType() == typeof(InsertPictureCommand))
{
e.Cancel = true;
}
else if (e.Command.GetType() == typeof(PasteCommand))
{
e.Cancel = true;
// Obtain the document inside the clipboard
RadDocument document = ClipboardEx.GetDocument().ToDocument();
// Change it according to your needs
document.Selection.SelectAll();
RadDocumentEditor editor = new RadDocumentEditor(document);
IEnumerable<ImageInline> images = document.EnumerateChildrenOfType<ImageInline>();
foreach (var image in images.ToList())
{
image.Parent.Children.Remove(image);
}
// Insert it in RadRichTextBox
this.radRichTextBox.InsertFragment(new DocumentFragment(document));
}
}
Regards,
Martin
Progress Telerik