Get a control from clipboard

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I can use following codes to set and get object (serializable class)
from Clipboar

Clipboard.SetDataObject(obj)

then

DataObject data=new DataObject()
obj=(ClassType)data.GetData(typeof(ClassType))

In the book Windows with C# (author Charles Petzold), it says a Button can be set or got from clipboard

I tried it. I can save it into clipboard. But after executing GetDate(); the obj is still null. In other word, I canno
get it from clipboard

Can you tell how to get a control or user control from clipboard

Thank

Keith
 
Hi Keith.

The objects you want to retrieve from clipboard must be marked as serializable (this is a conclusion from my tests).

Sample code is:


[Serializable]
public class ABC
{
string s;
int i;
public ABC()
{
s="ABC";
i=1;
}
}


ABC obj = new ABC ();

Clipboard.SetDataObject (obj);
obj = null;
obj = (ABC) Clipboard.GetDataObject ().GetData (typeof (ABC));
Console.WriteLine (obj.ToString ());

and it works and retrives the custom class object from clipboard.
 
Cezary

I knew it worked for serializable class because I had tried it.

My question was control, e.g. Button as following not user defined serializable clas

In the book WINDOWS WITH C# (author Charles Petzold), it says even a Button object ca
be set into and get from clipboard

I found out that I could set a Button object into clipboard because I checked it was in clipboard with

data.GetDataPresent(typeof(Button)

But when getting in from clipboard, it didn't work. No error message came out either

Do you know anything special to use clipboard with a control like Button

Thank
Keith
 
Can you post a sample project or a link to a project? Or send it zipped to
my email address (remove anti spams).

I shall play with it.

--
Cezary Nolewajka
mailto:[email protected]
remove all "no-sp-am-eh"s to reply

keith said:
Cezary,

I knew it worked for serializable class because I had tried it.

[...]
 
Back
Top