简体   繁体   English

用C#复制并粘贴

[英]Copy and paste with C#

I know this is asked many times before but it s not what i look for, to make copy paste in c# we use; 我知道这个问题以前曾被问过很多次,但这不是我想要的,要在我们使用的c#中粘贴复制;

//Copy
Clipboard.SetDataObject("String to copy"); 

//Paste
IDataObject iData = Clipboard.GetDataObject(); 

I only want to use copy, after using: 我只想在使用后使用副本:

Clipboard.SetDataObject("String to copy"); 

when i close the program, then when i right click and paste on a txt file nothing happens! 当我关闭程序时,然后当我右键单击并粘贴到txt文件时,什么也不会发生!
So Clipboard class seems doesnt help, so i need another solution. 所以剪贴板类似乎无济于事,所以我需要另一个解决方案。

Clipboard.SetDataObject("String to copy", true);

末尾的布尔值指定在应用程序关闭后是否应将字符串保留在剪贴板中,并且默认设置为false。

You want to use second overload of SetDataObject(object, bool) . 您想使用SetDataObject(object,bool)的第二次重载。

When bool is set to true , data will remain after application is closed. bool设置为true ,在应用程序关闭后数据将保留。

Did you try to use Clipboard.SetText(your_String) ? 您是否尝试使用Clipboard.SetText(your_String)
This works for me. 这对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM