Clipboard and Custom Types

This is a discussion on Clipboard and Custom Types within the C# Programming forums, part of the General Programming Boards category; Hello, I've been trying like crazy to figure out how to copy an object of a custom type to the ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    3

    Clipboard and Custom Types

    Hello,
    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
    BMJ
    BMJ is offline
    Banal internet user BMJ's Avatar
    Join Date
    Aug 2002
    Location
    Chicagoland
    Posts
    1,380
    If you want to use custom objects with the managed clipboard functions, the object must be declared as [Serializable()].

    Code:
    [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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21