set and get data from clipboard

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

Guest

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
 
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! :-)
 
Back
Top