[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.sdk

copy to clipboard with custom data format does not work

Markus

1/2/2003 2:19:00 PM

Hi,



The following sample is part of the Visual Studio .NET
Online help, but it doesn't work. Until now I was not able
to store data in a custom data format in the clipboard and
retrieve it back within the .NET platform.
On retrieving the data back I always receive a null handle.



How can this be achieved?



Best regards

Markus Buchberger



using System;
using System.Windows.Forms;

public class MyClass : Form {
protected TextBox textBox1;

public void MyClipboardMethod() {
// Creates a new data format.
DataFormats.Format myFormat = DataFormats.GetFormat
("myFormat");

/* Creates a new object and stores it in a
DataObject using myFormat
* as the type of format. */
MyNewObject myObject = new MyNewObject();
DataObject myDataObject = new DataObject
(myFormat.Name, myObject);

// Copies myObject into the clipboard.
Clipboard.SetDataObject(myDataObject);

// Performs some processing steps.

// Retrieves the data from the clipboard.
IDataObject myRetrievedObject =
Clipboard.GetDataObject();

// Converts the IDataObject type to MyNewObject
type.
MyNewObject myDereferencedObject = (MyNewObject)
myRetrievedObject.GetData(myFormat.Name);

// Prints the value of the Object in a textBox.
textBox1.Text = myDereferencedObject.MyObjectValue;
}
}

// Creates a new type.
public class MyNewObject : Object {
private string myValue;

// Creates a default constructor for the class.
public MyNewObject() {
myValue = "This is the value of the class";
}

// Creates a property to retrieve or set the value.
public string MyObjectValue {
get {
return myValue;
}
set {
myValue = value;
}
}
}

2 Answers

Mark Hurd

1/5/2003 4:21:00 PM

0

Markus wrote:
> Hi,
>
>
>
> The following sample is part of the Visual Studio .NET
> Online help, but it doesn't work. Until now I was not able
> to store data in a custom data format in the clipboard and
> retrieve it back within the .NET platform.
> On retrieving the data back I always receive a null handle.
>
>
>
> How can this be achieved?
>
>
>
> Best regards
>
> Markus Buchberger

I haven't reviewed your code thoroughly, but I've found the .NET Clipboard
support requires an active Windows message loop, especially when setting data.
See if your tests work when the "copy" and "paste" are in separate events.

Regards,
Mark Hurd, B.Sc.(Ma.) (Hons.)


Markus

1/5/2003 5:29:00 PM

0

thanks. I found the problem meanwhile. I forgot to mark the class that is copied to the clipboard as serializable.

thanks anyway.

markus