473,782 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.SetDa taObject(a)

IDataObject data=Clipboard. GetDataObject()
ABC b=null
if (data.GetDataPr esent(typeof(AB C))) // it returns true, that mens the data object is in clipboar
b=(ABC)data.Get Date(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 3244
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*******@disc ussions.microso ft.com> wrote in message news:0A******** *************** ***********@mic rosoft.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.SetDa taObject(a);

IDataObject data=Clipboard. GetDataObject() ;
ABC b=null;
if (data.GetDataPr esent(typeof(AB C))) // it returns true, that mens the data object is in clipboard
b=(ABC)data.Get Date(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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2689
by: TC | last post by:
Hello, I am familiar with obtaining source file reference material from the system clipboard using the old Win32 API. For example, copy an Excel chart onto the clipboard and goto Word. Under, Edit & PasteSpecial, there is a label called "Source:" which will contain the file path, etc. How can one obtain the source file reference material utilizing .Net
1
1989
by: VB User | last post by:
Earlier in VB6, the image was copied onto the clipboard from the Image Processing Program . This image would then be loaded onto the image control on the VB form using GetData() function. In VB.NET there is no image control for one and I get a type cast error while trying to save the contents of the clipboard using GetData() as an image Any help on this? VBUser
1
1831
by: Nukeation | last post by:
My app has to temporarily use the clipboard - and while doing so, it would delete any existing data which the user has copied (possibly from other applications). What I want to do is temporarily store (if to file then by serializing) the clipboard data, use the clipboard, and the restore the clipboard with the temp data. The question is: apps like Word store up to 16 different formats at once on the clipboard - how do I deal with...
6
7146
by: Andy | last post by:
I'm making a drag and drop application, and in the *_DragDrop(...)-method I have the following code: private void SelectTree_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) { Object item = (object)e.Data.GetData(typeof(AbstractNode)); // Other code }
2
3265
by: Shayne H | last post by:
I am trying to write a method to copy some text to the clipboard, and leave a copy of it there after the application has exited. Sub CopyToClipboard(ByVal value As Object) Dim data As New DataObject() data.SetData(DataFormats.UnicodeText, True, value) Clipboard.SetDataObject(data,True) End Sub When I test it, I get an exception:
2
9650
by: yxq | last post by:
Hello I want to get Windows clipboard data size, seem to use the function "GetClipboardDataSize". Could anyone please tell how to do using vb.net? Thanks
4
6527
by: MARTIN LANNY | last post by:
This is how I setup clipboard in my application: dim template as string = "put to clipboard" Clipboard.SetDataObject(template) And it all works like a charm until I close my program. As soon as the program is closed I lose the clipboard as well. Is there any way to keep the data in clipboard even that my application is already closed?
1
3985
by: Robert Bravery | last post by:
Hi all, I'm using the following code to copy data from XL to the clipboard to be later usied in a datatable range = objSheet.get_Range("A22", "aa100"); range.Copy(Missing.Value).ToString(); xlcopydata = Clipboard.GetData(DataFormats.Text).ToString(); Clipboard.Clear(); But when I issue a excelapplication quite I get an dialog saying that I have large amounts of data on the clipboard, do I want to keep it etc etc
5
2879
by: cgd | last post by:
hi, i want to save the MS Word data (not the Word file) to a database, so i copy the Word data to clipboard first,and then get the data to a DataObject object, and then try the code below, Formatter.Serialize(StreamTemp, dbObject); //but it can't be Serialized, StreamTemp.Close(); Return StreamTemp.GetBuffer() ;
0
9641
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10146
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6735
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2875
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.