469,927 Members | 1,781 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

set and get data from clipboard

I read a book, Programming Microsoft WINDOWS with C# by Charles Petzold, which shows ho
to set or get string and image to and from Clipboard. It says even a button object can be set or go
to and from a Clipboard

I defined a class, e.g

public class AB

string s
int i
public ABC(

s="ABC"
i=1

the

ABC a=new ABC()
Clipboard.SetDataObject(a)

IDataObject data=Clipboard.GetDataObject()
ABC b=null
if (data.GetDataPresent(typeof(ABC))) // it returns true, that mens the data object is in clipboar
b=(ABC)data.GetDate(typeof(ABC)); // but after the statement, b is still nul

Do you know what is problem

In our app, we need to set a complex class (UI) to Clipboard. I'm not sure if clipboard works fo
any kind object. Please advise

Thank

Keit

Nov 15 '05 #1
1 3039
Hi Keith,

If you want to get the object back, you need to add [Serializable] attribute to your class:

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

Then the rest of your code starts working... :-) Happy clipboarding! :-)

--
Cezary Nolewajka
mailto:c.*********************@no-sp-am-eh-mail.com
remove all "no-sp-am-eh"s to reply

"keith" <an*******@discussions.microsoft.com> wrote in message news:0A**********************************@microsof t.com...
I read a book, Programming Microsoft WINDOWS with C# by Charles Petzold, which shows how
to set or get string and image to and from Clipboard. It says even a button object can be set or got
to and from a Clipboard.

I defined a class, e.g.

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

then

ABC a=new ABC();
Clipboard.SetDataObject(a);

IDataObject data=Clipboard.GetDataObject();
ABC b=null;
if (data.GetDataPresent(typeof(ABC))) // it returns true, that mens the data object is in clipboard
b=(ABC)data.GetDate(typeof(ABC)); // but after the statement, b is still null

Do you know what is problem?

In our app, we need to set a complex class (UI) to Clipboard. I'm not sure if clipboard works for
any kind object. Please advise.

Thanks

Keith




Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by VB User | last post: by
1 post views Thread by Nukeation | last post: by
2 posts views Thread by yxq | last post: by
1 post views Thread by Robert Bravery | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.