That is where I get confused. Do I declare it [Serializeable] and
implement the interfaces or inherit from DataObject and override?
The only example I've seen creates a DataObject and uses SetData
implicitly through the constructor.
You want to add the Serializable attribute to your type, and then pass
that type to SetData on a DataObject. You don't want to have to implement
IDataObject (or extend DataObject), you want to make the calls to
DataObject, passing your object.

Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
> That is where I get confused. Do I declare it [Serializeable] and
> implement the interfaces or inherit from DataObject and override?
[quoted text clipped - 6 lines]
>> serilizable, so if your struct/class is serializable, then you can just
>> add it as one item.
bern11 - 23 Jan 2008 03:49 GMT
I'm 1/2-way there. I can put the object on the clipboard and detect it
with, I just can't get it back. I can paste the bitmap, just not the
object:
DataObject copyObject = new DataObject();
DataFormats.Format myFormat = DataFormats.GetFormat("myCustomType");
copyObject.SetData(DataFormats.Bitmap, myClassObject.bitmap);
copyObject.SetData("myCustomType", myClassObject);
Clipboard.SetDataObject(copyObject);
...
if (Clipboard.ContainsData("myCustomType")) {
??? = Clipboard.GetData("myCustomType");
...
// Class declared like this...
[Serializable]
public class myClassObject
{
Bitmap bitmap;
... other fields
}
> You want to add the Serializable attribute to your type, and then pass
> that type to SetData on a DataObject. You don't want to have to implement
> IDataObject (or extend DataObject), you want to make the calls to
> DataObject, passing your object.
bern11 - 24 Jan 2008 00:40 GMT
I figured out the problem: One of my fields was an ImageAttributes data
type, and it didn't like being serialized. I set it to NonSerialzed and
everything worked. It was kindof annoying that my program compiled &
ran wihtout throwing an error, but it just didn't work... Whats up with
that?
> You want to add the Serializable attribute to your type, and then pass
> that type to SetData on a DataObject. You don't want to have to implement
> IDataObject (or extend DataObject), you want to make the calls to
> DataObject, passing your object.