views:

909

answers:

2

I'm trying to copy both an image from a file and text from a file to the clipboard. My intention is to then open a word document or an outlook email and paste both the text and the image in one standard paste command (CTRL-V for example). I can do both separately easily enough, but doing them both in one operation doesn't seem to work.

This is how I've got the two working as separate operations (only relevant code lines of course, with try/catch stripped out etc.):

Add Image to Clipboard:

...

Bitmap imageToAdd = new Bitmap(imageFilePath);
Clipboard.SetImage(imageToAdd);

...

Add Text to Clipboard:

...

StreamReader rdr = new StreamReader(textFilePath);
string text = rdr.ReadToEnd();

Clipboard.SetText(text);

...

I'm using c# and .net 2.0 framework and targeting Windows XP (and likely Vista in the near future).

TIA

+1  A: 

Maybe you could use SetDataObject which requires an Object parameter, you could use an object array?

The object array could hold your required data.

See this link:

http://msdn.microsoft.com/en-us/library/5b8kt5z4.aspx

dotnetdev
Will a program such as outlook or MS Word understand to display both objects if I do it with an array? I'll need to be able to open up whatever program and just press CTRL-V to paste both objects in at once.
Jason Down
+1  A: 

I noticed only an object can be passed in.

In that case, when the user presses the command to paste, your code could execute two functions, or one function recursively, and each time get the data you want and paste it in.

So, look at looping or recursion.

dotnetdev