Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

clipboard

Status
Not open for further replies.

seanbo

Programmer
Jun 6, 2003
407
0
0
GB
i'm having difficulty with the clipboard. i'm pulling off text and filedrops okay, but not objects that i'm placing on it myself. i placed an onbject of type 'NodeInfo' on the clipboard with this peice of code:

NodeInfo myNodeInfo = (nodeInfo)myNodes;
Console.WriteLine(myNodeInfo == null);
Clipboard.SetDataObject(myNodeInfo);

notice the writeline, i'll come back to that. the code i'm writing to paste things from the clipboard is shaping up like this:

if(myIDataObject.GetDataPresent("Statex.nodeInfo")){
nodeInfo temp = (nodeInfo)myIDataObject.GetData("Statex.nodeInfo");
Console.WriteLine(temp == null);
}

in the console i'm getting the output:

False
True

this means that the NodeInfo object wasn't null when it went onto the clipboard, but was when it came off.

any ideas?

____________________________________________________
If you like a post, show you care by giving it a <censored>.
 
UPDATE: it works fine if i change the NodiInfo object to a string

____________________________________________________
If you like a post, show you care by giving it a <censored>.
 
Try marking the class you want to copy with the [Serializable] attribute. Like this below:

Code:
[Serializable]
public struct Header
{
	public string Name;
	public int Version;
}

I tried your exact code above only with this Header struct and it works just fine.
 
Just one comment depending on what you want to do with the text in clipboard.
There is a problem when you will try to paste the string you loaded in Clipboard into an application, let say Notepad, console application or a Unix session but all have an option to Paste there some text from the clipboard.
It will not work and you should use System.Runtime.InteropServices and allmost the whole set of functions that manages the Clipboard and found in kernel32.dll and user32.dll such as :OpenClipboard, CloseClipboard, EmptyClipboard, GlobalAlloc(), GlobalLock(), GlobalUnLock(), SetClipboardData(), GlobalFree().
-obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top