Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / January 2008

Tip: Looking for answers? Try searching our database.

Help with Custom Format & Clipboard

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bern11 - 22 Jan 2008 02:56 GMT
I have an data structure with a bitmap as a member.  I want to be able
to copy the object to the clipboard and paste it back into my app as a
new object, or into another app as a bitmap.  It looks like the
dataobject class does this, but I'm not exactly sure how to set it up.

1)  Should I just make a DataObject and call SetData twice, once with a
Bitmap object and once with a custom object, or 2) should I inherit from
dataobject and overload?  1st one sounds easier.
Nicholas Paldino [.NET/C# MVP] - 22 Jan 2008 03:21 GMT
I believe if your structure/class is serializable, the DataObject class
will support placing it on the clipboard.  The Bitmap class is serilizable,
so if your struct/class is serializable, then you can just add it as one
item.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

>I have an data structure with a bitmap as a member.  I want to be able to
>copy the object to the clipboard and paste it back into my app as a new
[quoted text clipped - 4 lines]
> Bitmap object and once with a custom object, or 2) should I inherit from
> dataobject and overload?  1st one sounds easier.
bern11 - 22 Jan 2008 05:26 GMT
    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.

>    I believe if your structure/class is serializable, the DataObject
> class will support placing it on the clipboard.  The Bitmap class is
> serilizable, so if your struct/class is serializable, then you can just
> add it as one item.
Nicholas Paldino [.NET/C# MVP] - 22 Jan 2008 15:06 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.