c# RTB - paste plain text without colours/fonts?

前端 未结 10 1380
感动是毒
感动是毒 2021-02-06 07:42

I am using Rich Text object in my C# application. The only issue I am having is that when user pastes formated text from another app, it remains formated which I cannot have. Is

10条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-06 08:07

    My solution

    private void OnCommandExecuting(object sender, Telerik.Windows.Documents.RichTextBoxCommands.CommandExecutingEventArgs e)
    {
        if (e.Command is PasteCommand)
        {
            //override paste when clipboard comes from out of RichTextBox (plain text)
            var documentFromClipboard = ClipboardEx.GetDocumentFromClipboard("RadDocumentGUID");
            if (documentFromClipboard == null)
            {
                (sender as RichTextBox).Insert(Clipboard.GetText());
                e.Cancel = true;
            }
        }
    }
    

提交回复
热议问题