I am attempting to create a Clipboard stack in C#. Clipboard data is stored in System.Windows.Forms.DataObject
objects. I wanted to store each clipboard entry (IDataObject
) directly in a Generic list. Due to the way Bitmaps (seem to be) stored I am thinking I need to perform a deep copy first before I add it to the list.
I attempted to use Binary serialization (see below) to create a deep copy but since System.Windows.Forms.DataObject
is not marked as serializable the serialization step fails. Any ideas?
public IDataObject GetClipboardData()
{
MemoryStream memoryStream = new MemoryStream();
BinaryFormatter binaryFormatter = new BinaryFormatter();
binaryFormatter.Serialize(memoryStream, Clipboard.GetDataObject());
memoryStream.Position = 0;
return (IDataObject) binaryFormatter.Deserialize(memoryStream);
}