.NETGURU
clipboard
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.windowsforms.

Post a new message to this list...

Pascal Cloup
Hello,

Is it possible to put in the Clipboard, an object which implements the
IDataObject interface but that knows only a format that is not defined in
the DataFormats?
What i want to do is to pull an object from the clipboard lke this:

IDataObject pulledObject = Clipboard.GetDataObject();

if ( pulledObject != null && pulledObject.GetDataPresent(
"MyObjectFormat" ) )

{

CMyClass A = pulledObject.GetData( "MyObjectFormat") as
CMyClass;

}

Pascal

Reply to this message...
 
    
ClayB [Syncfusion]
Here are two button handlers that put an arbitrary object into a DataObject,
places this DataObject on the Clipboard and then retrieves it.

private void button1_Click(object sender, System.EventArgs e)
{
MyObject o = new MyObject(18);
DataObject data = new DataObject("Mine", o);
Clipboard.SetDataObject(data);
}

private void button2_Click(object sender, System.EventArgs e)
{
if(Clipboard.GetDataObject().GetDataPresent("Mine"))
{
MyObject o = Clipboard.GetDataObject().GetData("Mine") as MyObject;
Console.WriteLine(o);
}
}

=================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools

"Pascal Cloup" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Pascal Cloup
Hello Clay,

Thanks for your answer.

I tried what you have suggested in the following manner:

rather than transmit to DataObject an object (A) of my original classe(CA) ,
i transmit an object B of a class (CB) that implements the ISerializable
interface and that describes A. (CA can not be serialized because it is
derived from Control).

When pushing B in the clipboard with :
DataObject D = new DataObject ("Mine",B);
Clipboard.SetDataObject( D, true);

, the method GetObjectData of B is normally called. But When i try to
recover my object from the clipboard i always get a nul reference.

Probably, i miss something, but what?

someone have an idea?

Pascal

"ClayB [Syncfusion]" <Click here to reveal e-mail address> a écrit dans le message de
news:%Click here to reveal e-mail address...
> Here are two button handlers that put an arbitrary object into a
DataObject,
[Original message clipped]

Reply to this message...
 
    
ClayB [Syncfusion]
You might try this. Instead of putting B on the clipboard, put a
memorystream that was created from B through serialization. Then get the
memory stream from the clipboard and use serilization to reconstruct B when
you get ready to paste.

=======================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools

"Pascal Cloup" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Pascal Cloup
Hello Clay,

"> You might try this. Instead of putting B on the clipboard, put a
[Original message clipped]

I didn't find how to create a MemoryStream object from an object like B that
is a serializable object.
Can-you give a example or a link? the documentation doesn't contain
sufficient details.

thanks in advance
Pascal

[Original message clipped]

Reply to this message...
 
    
Pascal Cloup
Hello Clay,

"> You might try this. Instead of putting B on the clipboard, put a
[Original message clipped]

I didn't find how to create a MemoryStream object from an object like B that
is a serializable object.
Can-you give a example or a link? the documentation doesn't contain
sufficient details.

thanks in advance
Pascal

[Original message clipped]

Reply to this message...
 
    
ClayB [Syncfusion]
Attached is a little sample that places an an object on the clipboard and is
able to retrieve it. It does not have to use any serialization as I
suggested earlier. The object has both simple types and a derived object as
members.

=================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools

"Pascal Cloup" <Click here to reveal e-mail address> wrote in message
news:%23F%Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Pascal Cloup
Thank you

I saw where the error was in my code. My serializable class didn't have a
constructor like:
protected MyObject(SerializationInfo info, StreamingContext context)

After verifications, the documentation doesn't indicate that such
constructor have to be implemented.

kind greetings

Pascal
"ClayB [Syncfusion]" <Click here to reveal e-mail address> a écrit dans le message de
news:Click here to reveal e-mail address...
> Attached is a little sample that places an an object on the clipboard and
is
[Original message clipped]

Reply to this message...
 
 
System.Console
System.EventArgs
System.IO.MemoryStream
System.Runtime.Serialization.ISerializable
System.Runtime.Serialization.SerializationInfo
System.Runtime.Serialization.StreamingContext
System.Security.Cryptography.Xml.DataObject
System.Windows.Forms.Clipboard
System.Windows.Forms.DataFormats
System.Windows.Forms.DataObject
System.Windows.Forms.IDataObject




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification