Can I Store more than 1 type in the Clipboard? Eg. like Text & Image. say the user pastes in a text editor, he gets the text and if he pastes in something like photoshop, he gets the image. I thought it was possible but I tried
Clipboard.Clear();
Clipboard.SetText(img.DirectLink);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.UriSource = new Uri(img.DirectLink);
bitmapImage.EndInit();
Clipboard.SetImage(bitmapImage);
and I always get the image
Yes, it is possible. The main problem is, methods you are using clear clipboard before putting data (that's why in particular they named "Set..." instead of "Add...").
Clipboard.SetText (WinForms) / Clipboard.SetText (WPF) description from MSDN:
But a solution is relatively easy:
Check MSDN for details:
WinForms: http://msdn.microsoft.com/en-us/library/25w5tzxb.aspx
WPF: http://msdn.microsoft.com/en-us/library/system.windows.clipboard.aspx
UPDATE:
Added links to WPF variants.
To clarify @Björn comment:
Both methods (WPF/WinForms) internally calls to OleSetClipboard so behaviour is similar (you can check http://referencesource.microsoft.com/#q=Clipboard.SetText).
I also checked both variants (WinForms/WPF) in console app and found they do the same.
As Nick says in the accepted answer: You have to use a DataObject (or IDataObject) to use multiple formats (otherwise each Set-call will clear the clipboard first).
Here is a code sample: