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




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com