如何复制数据在C#到剪贴板
问题描述:
我怎么能一个字符串拷贝(如你好)到系统剪贴板在C#中,所以下一次我preSS CTRL + V 骨节病>我会得到你好?
How can I copy a string (e.g "hello") to the System Clipboard in C#, so next time I press CTRL+V I'll get "hello"?
答
您将需要一个命名空间声明:
You'll need a namespace declaration:
using System.Windows.Forms;
或WPF的:
using System.Windows;
要复制一个确切的字符串(文字在这种情况下):
To copy an exact string (literal in this case):
Clipboard.SetText("Hello, clipboard");
要复制一个文本框的内容:
To copy the contents of a textbox:
Clipboard.SetText(txtClipboard.Text);