Thread: Clipboard and Custom Types

  1. #1
    Registered User
    Join Date
    Sep 2004

    Clipboard and Custom Types

    I've been trying like crazy to figure out how to copy an object of a custom type to the Clipboard via Clipboard.SetDataObject() and then retrieve it with Clipboard.GetDataObject().

    I've tried everything I can think of. I declare a DataObject, made out of my custom object, and give it a format name, and send it to the clipboard. Then I bring it back from the clipboard, as an IDataObject, use GetDataPresent(*format name", true), and it says that the data is present. But when I use GetData, it returns null! What is going on here?

    There are many demos about how to use the clipboard with strings and bitmaps but that's pretty useless. What's the point of C#'s clipboard support if all you can do is transfer bitmaps? I can post code if anyone is interested.

  2. #2
    Banal internet user
    Join Date
    Aug 2002
    If you want to use custom objects with the managed clipboard functions, the object must be declared as [Serializable()].

    public class CustomData
    ... blah blah blah ...
    Basically when custom objects are sent to the clipboard they're serialized, and then the clipboard holds the binary data.

Popular pages Recent additions subscribe to a feed