set and get data from clipboard

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
 
C

Cezary Nolewajka

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

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