DataObject Constructor (String, Object)

 

Initializes a new instance of the DataObject class and adds the specified object in the specified format.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public DataObject(
	string format,
	object data
)

Parameters

format
Type: System.String

The format of the specified data. See DataFormats for predefined formats.

data
Type: System.Object

The data to store.

The following code example creates a DataObject class using a string that is specified as the string type. The data is retrieved from the DataObject by specifying its format as text. The results are displayed in a text box. This code requires that textBox1 has been created.

private void CreateTextDataObject2() {
    // Creates a new data object using a string.
    string myString = "My next text string";
    DataObject myDataObject = new DataObject("System.String", myString);

    // Prints the string in a text box.
    textBox1.Text = myDataObject.GetData(DataFormats.Text).ToString();
 }

.NET Framework
Available since 1.1
Return to top
Show: