แก้ไข

แชร์ผ่าน


DataObject Constructors

Definition

Initializes a new instance of the DataObject class.

Overloads

DataObject()

Initializes a new instance of the DataObject class.

DataObject(Object)

Initializes a new instance of the DataObject class and adds the specified object to it.

DataObject(String, Object)

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

DataObject()

Source:
DataObject.cs
Source:
DataObject.cs
Source:
DataObject.cs

Initializes a new instance of the DataObject class.

public:
 DataObject();
public DataObject ();
Public Sub New ()

Examples

The following code example creates a DataObject and adds data to it. The example then retrieves and displays the data. This code requires that textBox1 has been created.

private:
   void CreateDefaultDataObject()
   {
      // Creates a data object.
      DataObject^ myDataObject;
      
      // Assigns the string to the data object.
      String^ myString = "My text string";
      myDataObject = gcnew DataObject( myString );
      
      // Prints the string in a text box.
      textBox1->Text = myDataObject->GetData( DataFormats::Text )->ToString();
   }
private void CreateDefaultDataObject() {
    // Creates a data object.
    DataObject myDataObject;
 
    // Assigns the string to the data object.
    string myString = "My text string";
    myDataObject = new DataObject(myString);
 
    // Prints the string in a text box.
    textBox1.Text = myDataObject.GetData(DataFormats.Text).ToString();
 }
Private Sub CreateDefaultDataObject()
    ' Creates a data object.
    Dim myDataObject As DataObject
    
    ' Assigns the string to the data object.
    Dim myString As String = "My text string"
    myDataObject = New DataObject(myString)
    
    ' Prints the string in a text box.
    textBox1.Text = myDataObject.GetData(DataFormats.Text).ToString()
End Sub

See also

Applies to

DataObject(Object)

Source:
DataObject.cs
Source:
DataObject.cs
Source:
DataObject.cs

Initializes a new instance of the DataObject class and adds the specified object to it.

public:
 DataObject(System::Object ^ data);
public DataObject (object data);
new System.Windows.Forms.DataObject : obj -> System.Windows.Forms.DataObject
Public Sub New (data As Object)

Parameters

data
Object

The data to store.

Examples

The following code example creates a DataObject that contains a string. The data is retrieved using its data format. The results are displayed in a text box. This code requires that textBox1 has been created.

private:
   void CreateTextDataObject()
   {
      // Creates a new data object using a string.
      String^ myString = "My text string";
      DataObject^ myDataObject = gcnew DataObject( myString );
      
      // Prints the string in a text box.
      textBox1->Text = myDataObject->GetData( DataFormats::Text )->ToString();
   }
private void CreateTextDataObject() {
    // Creates a new data object using a string.
    string myString = "My text string";
    DataObject myDataObject = new DataObject(myString);
 
    // Prints the string in a text box.
    textBox1.Text = myDataObject.GetData(DataFormats.Text).ToString();
 }
Private Sub CreateTextDataObject()
    ' Creates a new data object using a string.
    Dim myString As String = "My text string"
    Dim myDataObject As New DataObject(myString)
    
    ' Prints the string in a text box.
    textBox1.Text = myDataObject.GetData(DataFormats.Text).ToString()
End Sub

Remarks

You can add data in any format to the DataObject when you use this constructor, or you can add data as an IDataObject to provide multiple formats at once. If you are familiar with COM programming, you can also add a data object that implements the COM IDataObject interface. For more information, see IDataObject.

See also

Applies to

DataObject(String, Object)

Source:
DataObject.cs
Source:
DataObject.cs
Source:
DataObject.cs

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

public:
 DataObject(System::String ^ format, System::Object ^ data);
public DataObject (string format, object data);
new System.Windows.Forms.DataObject : string * obj -> System.Windows.Forms.DataObject
Public Sub New (format As String, data As Object)

Parameters

format
String

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

data
Object

The data to store.

Examples

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 = gcnew DataObject( "System.String",myString );
      
      // Prints the string in a text box.
      textBox1->Text = myDataObject->GetData( DataFormats::Text )->ToString();
   }
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();
 }
Private Sub CreateTextDataObject2()
    ' Creates a new data object using a string.
    Dim myString As String = "My next text string"
    Dim myDataObject As New DataObject("System.String", myString)
    
    ' Prints the string in a text box.
    textBox1.Text = myDataObject.GetData(DataFormats.Text).ToString()
End Sub

See also

Applies to