Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have problem when work with clipboard in C# and i search over time in internet but
I cant find everything for my problems! Please help me.

I need copy both of image and text to Clipboard so I use:
C#
//gdiBitmap is BitmapSource:
DataObject dataObj = new DataObject(); 
dataObj.SetData(DataFormats.Bitmap, gdiBitmap); 
dataObj.SetData(DataFormats.Text, " Text Copy Image To Clipboard");
Clipboard.SetDataObject(dataObj, true);

but I cant pastes the content in clipboard to Microsoft Word or Excel.
It is Only pastes the text "Text Copy Image To Clipboard" and my image is nothing.

but if i only copy one Image or text it's ok!

Thanks for Help!
Posted
Updated 10-Jan-12 21:12pm
v3

1 solution

Hi,

Try to copy something from word, and then run this code in a C# project:

C#
object rtfData = Clipboard.GetData(DataFormats.Rtf);
Clipboard.SetData(DataFormats.Rtf, rtfData);


You will see that Word puts data in Clipboard in RTF format.

In order for you to make the same thing, you must put into clipboard RTF data format.

In your example if you paste in word, it will copy the text from Clipboard, and if you paste in Paint it will copy the Image.

Every external program parse the data from Clipboard in his own way.

Hope this helps.
 
Share this answer
 
Comments
quy_sau000 11-Jan-12 18:12pm    
Thanks Incaunu! I think it's good solves for my problem. I will try!
quy_sau000 12-Jan-12 2:19am    
Hi ALL!
I have solved my problem copy Image and text from Application C# to Word!(Thanks incaunu ^^. I used RTF format to do that) But it's not work with Excell,Paint,notepad...(so sad)
And I have tried copy from Microsoft word and pastes to Excell, paint,notepad...Amazing it's good.
So I don't know Achitecture or structure of Clipboard Microsoft Office, how it can do that. Anybody can Answer for me.

Thanks for help.
Member 11064511 22-Sep-14 23:49pm    
the webpage been selected by htmlDoc.ExecCommand("selectALL", false, null);
htmlDoc.ExecCommand("Copy", true, null);but i wanted to save the clipboard content to ms word , but i could'nt because the codings are so confused and hard to understand .moreover i want to delete some selected area on clipboard before it is being saved to ms word and the command shold creat the ms word file name programatically.i use win 7 profissional/32 bit, vs 2010/32 bit,ms word 2007.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900