Initializes a new instance of the DataObject class, containing the specified data and its associated format.
[Visual Basic] Overloads Public Sub New( _ ByVal format As String, _ ByVal data As Object _ ) [C#] public DataObject( string format, object data ); [C++] public: DataObject( String* format, Object* data ); [JScript] public function DataObject( format : String, data : Object );
The new instance provides both the IDataObject and the Microsoft.Win32.Interop.IOleDataObject interfaces for the specified data.
CAUTION Creating an instance of DataObject with an object that implements both the IDataObject and Microsoft.Win32.Interop.IOleDataObject interfaces causes a design-time or run-time error. To avoid this problem, first convert the object either to an IDataObject or to an Microsoft.Win32.Interop.IOleDataObject.
The following example creates an instance of the DataObject class using a string that is specified as text format. The data is retrieved from the instance by specifying its format as text. Then the data is displayed in a text box. This code assumes Button1 and TextBox1 have been instantiated.
[C#]
private void CreateDataObject() { //Create a new data object using a string. string myString = "My text string"; DataObject myDataObject = new DataObject(DataFormats.Text, myString); //Print the string in a text box. textBox1.Text = myDataObject.GetData(DataFormats.Text).ToString(); }
DataObject Class | DataObject Members | System.WinForms Namespace | DataObject Constructor Overload List | GetData | SetData | GetDataPresent