Hello!
I am using the clipboard in my application to insert images into a
RichTextBox. This works fine. What doesn't work fine is that the original
information in the clipboard get corrupted. To prvent this I try to save the
original clipboard data to a IDataObject before using the clipboard and then
when I'm finished I put the original data back to the clipboard. This also
works fine, except when repeated twice. Sounds strange? it is!
This is my code:
*******************************************************************
DataObject orgObject = Clipboard.GetDataObject() as DataObject;
// some more code
Clipboard.SetDataObject(seg.Image);
DataFormats.Format format = DataFormats.GetFormat(DataFormats.Bitmap);
richTextBox1.ReadOnly = false;
if (richTextBox1.CanPaste(format))
richTextBox1.Paste(format);
// other code
Clipboard.SetDataObject(orgObject,true)
*******************************************************************
Everything works just fine when this code is first run. The data that
originally was in the clipboard still is there. Though, when run secondly
the last line of code throws an exception. It is an external exception with
errorcode -2147221036 which means "CloseClipboard Failed". Why does this
happen? And why doesn't it occour the first time the code is run?
Any help appreciated.
/David.