Approved
Last Updated: 04 Oct 2016 08:06 by ADMIN
ADMIN
Dimitar
Created on: 06 Sep 2016 05:10
Category: RichTextBox (obsolete)
Type: Bug Report
1
FIX. RadRichTextEditor - the already set default font is not respected when a plain text is pasted.
To reproduce:
- Change the font of the new document:
txtCustomerInstallation.Document = new RadDocument();
txtCustomerInstallation.RichTextBoxElement.ChangeFontFamily(new Telerik.WinControls.RichTextEditor.UI.FontFamily("Calibri"));
txtCustomerInstallation.RichTextBoxElement.ChangeFontSize(Unit.PointToDip(10));
txtCustomerInstallation.RichTextBoxElement.ChangeParagraphSpacingAfter(0.0);

txtCustomerInstallation.DocumentInheritsDefaultStyleSettings = true;

- Start and paste plain text.
- The font os changed to Verdana. 


Workaround:
void radRichTextEditor1_CommandExecuting(object sender, CommandExecutingEventArgs e)
{
    if (e.Command is PasteCommand)
    {
        e.Cancel = true;
        PasteNewText();
    }
}

public void PasteNewText()
{
    DocumentFragment clipboardDocument = null;
    string clipboardText = null;
    bool clipboardContainsData = false;

    if (ClipboardEx.ContainsDocument(null))
    {
        clipboardDocument = ClipboardEx.GetDocument();
        clipboardContainsData = true;
    }
    else if (ClipboardEx.ContainsText(null))
    {
        clipboardText = ClipboardEx.GetText(null);
        clipboardContainsData = true;
    }

    if (!clipboardContainsData)
    {
        return;
    }

    if (clipboardDocument != null)
    {
        RadDocument doc = new RadDocument();
        RadDocumentEditor editor = new RadDocumentEditor(doc);
        editor.InsertFragment(clipboardDocument);
        doc.Selection.SelectAll();

        editor.ChangeFontFamily(new Telerik.WinControls.RichTextEditor.UI.FontFamily("Calibri"));
        DocumentFragment fragmentFromSelection = doc.Selection.CopySelectedDocumentElements();
        this.radRichTextEditor1.RichTextBoxElement.ActiveDocumentEditor.InsertFragment(fragmentFromSelection);
    }
    else if (!string.IsNullOrEmpty(clipboardText))
    {
        this.radRichTextEditor1.RichTextBoxElement.ActiveDocumentEditor.Insert(clipboardText);
    }
}

(Total attached files size should be smaller than 20mb. Allowed extensions: .zip, .rar, .jpg, .png, .gif)
0 comments