我想获取当前存储在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剪贴板


基础教程推荐
猜你喜欢
- C#集合查询Linq在项目中使用详解 2023-06-09
- c#中利用Tu Share获取股票交易信息 2023-03-03
- C#中类与接口的区别讲解 2023-06-04
- C#通过GET/POST方式发送Http请求 2023-04-28
- Unity shader实现多光源漫反射以及阴影 2023-03-04
- C# Winform实现石头剪刀布游戏 2023-01-11
- c#读取XML多级子节点 2022-11-05
- 京东联盟C#接口测试示例分享 2022-12-02
- C# – NetUseAdd来自Windows Server 2008和IIS7上的NetApi32.dll 2023-09-20
- 使用c#从分隔文本文件中插入SQL Server表中的批量数据 2023-11-24