[英]Save any Clipboard content and reload it?
我需要使用剪贴板 memory 1 秒,做一些事情,然后重新加载原始剪贴板。
我想让我的剪贴板做:
但是我的剪贴板做了什么:
using System.Windows.Forms;
public class ExplorerTools
{
public void Run()
{
// saving the current clipboard
var oldClipboard = Clipboard.GetDataObject();
// Doing some stuff with the clipboard
Clipboard.SetText("My Useful Text");
System.Threading.Thread.Sleep(400);
// I want to put back oldClipboard in the clipboard
Clipboard.SetDataObject(oldClipboard);
}
}
我不明白为什么Clipboard.SetDataObject()
无法检索旧值,他什么也没放 ='(
正如@Taw 所说,我不能直接使用从Clipboard.GetDataObject()
获得的 IDataObject。 所以我必须保存每 21 种剪贴板数据并自己单独重新加载。
using System.Windows.Forms;
public class ExplorerTools
{
public void Run()
{
// saving the current clipboard
string[] arr_format = Clipboard.GetDataObject().GetFormats(false);
Dictionary<string, object> dic_oldDataClipboard = new Dictionary<string, object>();
foreach(string format in arr_format)
dic_oldDataClipboard.Add(format, Clipboard.GetData(format));
// Doing some stuff with the clipboard
Clipboard.SetText("My Useful Text");
System.Threading.Thread.Sleep(400);
// I want to put back oldClipboard in the clipboard
foreach(var format_data in dic_oldDataClipboard)
Clipboard.SetData(format_data.Key, format_data.Value);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.