How to copy both - HTML and text to the clipboard?

前端 未结 1 1475
别那么骄傲
别那么骄傲 2021-01-12 07:02

I\'m trying to put in the clipboard piece of HTML and plain text at the same time, so that HTML-capable editors could paste HTML, and other editors could use plain text.

相关标签:
1条回答
  • 2021-01-12 07:28

    You can NOT use Clipboard.SetData for setting both HTML and plain text. The second call of SetData will clear the content of clipboard that has been set by first call and store the new data.

    You should use DataObject and Clipboard.SetDataObject().

    Example:

    DataObject dataObj = new DataObject();
    dataObj.SetData(DataFormats.Html, htmlWithHeader);
    dataObj.SetData(DataFormats.Text, plainText);
    
    Clipboard.SetDataObject(dataObj);
    
    0 讨论(0)
提交回复
热议问题