clipboard

P

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
 
C

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
 
P

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
 
C

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
 
P

Pascal Cloup

Hello Clay,


"> 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.

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
 
P

Pascal Cloup

Hello Clay,


"> 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.

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
 
C

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 said:
Hello Clay,


"> 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.

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
=======================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools

Pascal Cloup said:
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]" <[email protected]> a écrit dans le message de
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

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
 
P

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 said:
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 said:
Hello Clay,


"> 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.

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
=======================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools

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]" <[email protected]> a écrit dans le message de
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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top