如何同时复制 - html和文本复制到剪贴板? [英] How to copy both - html and text to the clipboard?

查看:369
本文介绍了如何同时复制 - html和文本复制到剪贴板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图把在clipoard片HTML,并在同一时间的纯文本,使HTML的编辑器可以粘贴HTML,和其他编辑可以使用纯文本。

I'm trying to put in the clipoard 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.

Clipboard.SetData(DataFormats.Html, htmlWithHeader); 
Clipboard.SetData(DataFormats.UnicodeText, plainText);

但只有最后一个格式居然把到剪贴板。在上面的示例,剪贴板将只包含明文(如图 Clipboard.GetDataObject()。getFormats返回())。如果我换行,剪贴板将只有html格式。

But only the last format is actually put to the clipboard. In the sample above, clipboard would contain only plaintext (as shown by Clipboard.GetDataObject().GetFormats() ). And if i swap the lines, clipboard would have only html format.

我怎样才能把两种格式复制到剪贴板在同一时间?

How can I put both formats into the clipboard at the same time?

推荐答案

你不能使用 Clipboard.SetData 设置HTML和纯文本,SetData的第二个呼叫将清除剪贴板已设置由第一呼叫的内容和存储新的数据。

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.

您应该使用数据对象和的 Clipboard.SetDataObject()

例如:

DataObject dataObj = new DataObject();
dataObj.SetData(DataFormats.Html, htmlWithHeader);
dataObj.SetData(DataFormats.Text, plainText);

Clipboard.SetDataObject(dataObj);

这篇关于如何同时复制 - html和文本复制到剪贴板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆