Mustafa Ekici
Mustafa Ekici

Reputation: 7480

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;

//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!
So Clipboard class seems doesnt help, so i need another solution.

Upvotes: 3

Views: 3453

Answers (3)

Andreas Eriksson
Andreas Eriksson

Reputation: 9027

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

That boolean value at the end specifies whether the string should remain in the clipboard after the application closes, and is set to false as default.

Upvotes: 6

k.m
k.m

Reputation: 31474

You want to use second overload of SetDataObject(object, bool).

When bool is set to true, data will remain after application is closed.

Upvotes: 3

Marco
Marco

Reputation: 57593

Did you try to use Clipboard.SetText(your_String)?
This works for me.

Upvotes: 1

Related Questions