DataObject::SetData Method (String^, Object^)
.NET Framework (current version)
Adds the specified object to the DataObject using the specified format.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Parameters
- format
-
Type:
System::String^
The format associated with the data. See DataFormats for predefined formats.
- data
-
Type:
System::Object^
The data to store.
Implements
IDataObject::SetData(String^, Object^)If you do not know the format of the target application, you can store data in multiple formats using this method.
Data stored using this method can be converted to a compatible format when it is retrieved.
The following code example stores data in a DataObject, specifying its format as Unicode.
Then the data is retrieved by specifying the text format, since the default is to convert the data when the final format is compatible. The result is displayed in a text box.
This code requires that textBox1 has been created.
private: void AddMyData() { // Creates a new data object using a string and the text format. DataObject^ myDataObject = gcnew DataObject; // Stores a string, specifying the Unicode format. myDataObject->SetData( DataFormats::UnicodeText, "Text string" ); // Retrieves the data by specifying Text. textBox1->Text = myDataObject->GetData( DataFormats::Text )->GetType()->Name; }
.NET Framework
Available since 1.1
Available since 1.1
Show: