我想获取当前存储在Windows剪贴板中的数据并将其保存在变量中,然后将数据放回剪贴板.现在我正在使用这段代码:object l_oClipBrdData = Clipboard.GetDataObject();Clipboard.SetDataObject(l_oClipBrdData ,true)...

我想获取当前存储在Windows剪贴板中的数据并将其保存在变量中,然后将数据放回剪贴板.
现在我正在使用这段代码:
object l_oClipBrdData = Clipboard.GetDataObject();
Clipboard.SetDataObject(l_oClipBrdData ,true);
但在这之后,剪贴板是空的.
我究竟做错了什么?
解决方法:
这是一个演示’剪贴板’对象的示例:
string text;
string[] a;
if (Clipboard.ContainsText())
{
text = Clipboard.GetText(TextDataFormat.Text);
// the following could have been done simpler with
// a Regex, but the regular expression would be not
// exactly simple
if (text.Length > 1)
{
// unify all line breaks to \r
text = text.Replace("\r\n", "\r").Replace("\n", "\r");
// create an array of lines
a = text.Split('\r');
// join all trimmed lines with a space as separator
text = "";
// can't use string.Join() with a Trim() of all fragments
foreach (string t in a)
{
if (text.Length > 0)
text += " ";
text += t.Trim();
}
Clipboard.SetDataObject(text, true);
}
}
织梦狗教程
本文标题为:c# – 从中获取数据然后返回Windows剪贴板


基础教程推荐
猜你喜欢
- Unity 如何获取鼠标停留位置下的物体 2023-04-10
- C#获取指定目录下某种格式文件集并备份到指定文件夹 2023-05-30
- Unity shader实现高斯模糊效果 2023-01-16
- C#通过标签软件Bartender的ZPL命令打印条码 2023-05-16
- C# 解析XML和反序列化的示例 2023-04-14
- C#中 Json 序列化去掉null值的方法 2022-11-18
- C#调用摄像头实现拍照功能的示例代码 2023-03-09
- 实例详解C#实现http不同方法的请求 2022-12-26
- c# – USING块在网站与Windows窗体中的行为不同 2023-09-20
- C#中的Linq to JSON操作详解 2023-06-08