IDataObject.SetData Metoda

Definicja

Przechowuje określone dane i skojarzony z nim format w tym wystąpieniu.

Przeciążenia

SetData(Object)

Przechowuje określone dane w tym wystąpieniu przy użyciu klasy danych dla formatu.

SetData(String, Object)

Przechowuje określone dane i skojarzony z nim format w tym wystąpieniu.

SetData(Type, Object)

Przechowuje określone dane i skojarzony typ klasy w tym wystąpieniu.

SetData(String, Boolean, Object)

Przechowuje określone dane i skojarzony z nim format w tym wystąpieniu, używając wartości logicznej w celu określenia, czy dane można przekonwertować na inny format.

SetData(Object)

Przechowuje określone dane w tym wystąpieniu przy użyciu klasy danych dla formatu.

public:
 void SetData(System::Object ^ data);
public void SetData (object data);
public void SetData (object? data);
abstract member SetData : obj -> unit
Public Sub SetData (data As Object)

Parametry

data
Object

Dane do przechowywania.

Przykłady

W tym przykładzie użyto DataObject klasy , która implementuje IDataObjectmetodę SetData , aby zademonstrować użycie metody . Najpierw tworzy składnik (myComponent) i zapisuje go w obiekcie danych (myDataObject). Następnie sprawdza, czy określone dane są przechowywane w obiekcie danych i wyświetla wynik w oknie komunikatu. W przykładzie założono, że utworzono Form nazwę Form1.

private:
   void SetData1()
   {
      // Creates a component to store in the data object.
      Component^ myComponent = gcnew Component;
      
      // Creates a data object.
      DataObject^ myDataObject = gcnew DataObject;
      
      // Adds the component to the data object.
      myDataObject->SetData( myComponent );
      
      // Checks whether data of the specified type is in the data object.
      Type^ myType = myComponent->GetType();
      String^ myMessageText;
      if ( myDataObject->GetDataPresent( myType ) )
      {
         myMessageText = "Data of type " + myType->Name +
            " is present in the data object";
      }
      else
      {
         myMessageText = "Data of type " + myType->Name +
            " is not present in the data object";
      }
      
      // Displays the result in a message box.
      MessageBox::Show( myMessageText, "The Test Result" );
   }
private void SetData1() 
{
    // Creates a component to store in the data object.
    Component myComponent = new Component();
 
    // Creates a data object.
    DataObject myDataObject = new DataObject();

    // Adds the component to the data object.
    myDataObject.SetData(myComponent);
 
    // Checks whether data of the specified type is in the data object.
    Type myType = myComponent.GetType();
    string myMessageText;
    if(myDataObject.GetDataPresent(myType))
         myMessageText = "Data of type " + myType.Name + 
            " is present in the data object";
    else
        myMessageText = "Data of type " + myType.Name +
            " is not present in the data object";

    // Displays the result in a message box.
    MessageBox.Show(myMessageText, "The Test Result"); 
}
Private Sub SetData1()
   ' Creates a component to store in the data object.
   Dim myComponent As New System.ComponentModel.Component()
   
   ' Creates a data object.
   Dim myDataObject As New DataObject()
   
   ' Adds the component to the data object.
   myDataObject.SetData(myComponent)
   
   ' Checks whether data of the specified type is in the data object.
   Dim myType As Type = myComponent.GetType()
   Dim myMessageText As String
   If myDataObject.GetDataPresent(myType) Then
      myMessageText = "Data of type " + myType.Name + " is present in the data object"
   Else
      myMessageText = "Data of type " + myType.Name + " is not present in the data object"
   End If

   ' Displays the result in a message box.
   MessageBox.Show(myMessageText, "The Test Result")
End Sub

Uwagi

Format pochodzi z klasy danych.

Dane przechowywane przy użyciu tej metody można przekonwertować na zgodny format podczas pobierania.

Aby zapoznać się z implementacją tej metody, zobacz DataObject.SetData.

Zobacz też

Dotyczy

SetData(String, Object)

Przechowuje określone dane i skojarzony z nim format w tym wystąpieniu.

public:
 void SetData(System::String ^ format, System::Object ^ data);
public void SetData (string format, object data);
public void SetData (string format, object? data);
abstract member SetData : string * obj -> unit
Public Sub SetData (format As String, data As Object)

Parametry

format
String

Format skojarzony z danymi. Zobacz DataFormats , aby zapoznać się ze wstępnie zdefiniowanymi formatami.

data
Object

Dane do przechowywania.

Przykłady

W tym przykładzie użyto DataObject klasy , która implementuje IDataObjectmetodę SetData , aby zademonstrować użycie metody . Najpierw tworzy obiekt danych (myDataObject) i przechowuje ciąg w obiekcie określającym UnicodeText format. Następnie pobiera te dane przechowywane w obiekcie określającym Text format, tak aby dane zostały przekonwertowane na Text format. Wynik jest wyświetlany w oknie komunikatu. W tym przykładzie przyjęto założenie, że utworzono Form nazwę Form1.

private:
   void SetData2()
   {
      // Creates a data object.
      DataObject^ myDataObject = gcnew DataObject;
      
      // Stores a string, specifying the UnicodeText format.
      myDataObject->SetData( DataFormats::UnicodeText, "Hello World!" );
      
      // Retrieves the data by specifying the Text format.
      String^ myMessageText = "The data type is " +
         myDataObject->GetData( DataFormats::Text )->GetType()->Name;
      
      // Displays the result.
      MessageBox::Show( myMessageText, "The Test Result" );
   }
private void SetData2() 
{
    // Creates a data object.
    DataObject myDataObject = new DataObject();
 
    // Stores a string, specifying the UnicodeText format.
    myDataObject.SetData(DataFormats.UnicodeText, "Hello World!");
 
    // Retrieves the data by specifying the Text format.
    string myMessageText = "The data type is " + myDataObject.GetData(DataFormats.Text).GetType().Name;

    // Displays the result.
    MessageBox.Show(myMessageText, "The Test Result");
}
Private Sub SetData2()
   ' Creates a data object.
   Dim myDataObject As New DataObject()
   
   ' Stores a string, specifying the UnicodeText format.
   myDataObject.SetData(DataFormats.UnicodeText, "Hello World!")
   
   ' Retrieves the data by specifying the Text format.
   Dim myMessageText As String = "The data type is " & _
             myDataObject.GetData(DataFormats.Text).GetType().Name
   
   ' Displays the result.
   MessageBox.Show(myMessageText, "The Test Result")
End Sub

Uwagi

Jeśli nie znasz formatu aplikacji docelowej, możesz przechowywać dane w wielu formatach przy użyciu tej metody.

Dane przechowywane przy użyciu tej metody można przekonwertować na zgodny format podczas pobierania.

Aby zapoznać się z implementacją tej metody, zobacz DataObject.SetData.

Zobacz też

Dotyczy

SetData(Type, Object)

Przechowuje określone dane i skojarzony typ klasy w tym wystąpieniu.

public:
 void SetData(Type ^ format, System::Object ^ data);
public void SetData (Type format, object data);
public void SetData (Type format, object? data);
abstract member SetData : Type * obj -> unit
Public Sub SetData (format As Type, data As Object)

Parametry

format
Type

Reprezentujący Type format skojarzony z danymi. Zobacz DataFormats , aby zapoznać się ze wstępnie zdefiniowanymi formatami.

data
Object

Dane do przechowywania.

Przykłady

W tym przykładzie użyto DataObject klasy , która implementuje IDataObjectmetodę SetData , aby zademonstrować użycie metody . Najpierw tworzy składnik (myComponent) i zapisuje go w obiekcie danych (myDataObject), używając polecenia myType w celu określenia formatu danych. Następnie sprawdza, czy dane określonego typu są przechowywane w obiekcie i wyświetla wynik w oknie komunikatu. W przykładzie założono, że utworzono Form nazwę Form1.

private:
   void SetData3()
   {
      // Creates a component.
      Component^ myComponent = gcnew Component;
      
      // Gets the type of the component.
      Type^ myType = myComponent->GetType();
      
      // Creates a data object.
      DataObject^ myDataObject = gcnew DataObject;
      
      // Stores the component in the data object.
      myDataObject->SetData( myType, myComponent );
      
      // Checks whether data of the specified type is in the data object.
      String^ myMessageText;
      if ( myDataObject->GetDataPresent( myType ) )
      {
         myMessageText = "Data of type " + myType->Name +
            " is stored in the data object";
      }
      else
      {
         myMessageText = "No data of type " + myType->Name +
            " is stored in the data object";
      }
      
      // Displays the result.
      MessageBox::Show( myMessageText, "The Test Result" );
   }
private void SetData3() 
{
    // Creates a component.
    Component myComponent = new Component();
 
    // Gets the type of the component.
    Type myType = myComponent.GetType();
 
    // Creates a data object.
    DataObject myDataObject = new DataObject();
 
    // Stores the component in the data object.
    myDataObject.SetData(myType, myComponent);
 
    // Checks whether data of the specified type is in the data object.
    string myMessageText;
    if(myDataObject.GetDataPresent(myType))
        myMessageText = "Data of type " + myType.Name + 
            " is stored in the data object";
    else
        myMessageText = "No data of type " + myType.Name +
            " is stored in the data object";
            
    // Displays the result.
    MessageBox.Show(myMessageText, "The Test Result");
}
Private Sub SetData3()
   ' Creates a component.
   Dim myComponent As New System.ComponentModel.Component()
   
   ' Gets the type of the component.
   Dim myType As Type = myComponent.GetType()
   
   ' Creates a data object.
   Dim myDataObject As New DataObject()
   
   ' Stores the component in the data object.
   myDataObject.SetData(myType, myComponent)
   
   ' Checks whether data of the specified type is in the data object.
   Dim myMessageText As String
   If myDataObject.GetDataPresent(myType) Then
      myMessageText = "Data of type " & myType.Name & " is stored in the data object"
   Else
      myMessageText = "No data of type " & myType.Name & " is stored in the data object"
   End If
   
   ' Displays the result.
   MessageBox.Show(myMessageText, "The Test Result")
End Sub

Uwagi

Jeśli nie znasz formatu aplikacji docelowej, możesz przechowywać dane w wielu formatach przy użyciu tej metody.

Dane przechowywane przy użyciu tej metody można przekonwertować na zgodny format podczas pobierania.

Aby zapoznać się z implementacją tej metody, zobacz DataObject.SetData.

Zobacz też

Dotyczy

SetData(String, Boolean, Object)

Przechowuje określone dane i skojarzony z nim format w tym wystąpieniu, używając wartości logicznej w celu określenia, czy dane można przekonwertować na inny format.

public:
 void SetData(System::String ^ format, bool autoConvert, System::Object ^ data);
public void SetData (string format, bool autoConvert, object data);
public void SetData (string format, bool autoConvert, object? data);
abstract member SetData : string * bool * obj -> unit
Public Sub SetData (format As String, autoConvert As Boolean, data As Object)

Parametry

format
String

Format skojarzony z danymi. Zobacz DataFormats , aby zapoznać się ze wstępnie zdefiniowanymi formatami.

autoConvert
Boolean

true aby umożliwić konwersję danych na inny format; w przeciwnym razie , false.

data
Object

Dane do przechowywania.

Przykłady

W tym przykładzie użyto DataObject klasy , która implementuje IDataObjectmetodę SetData , aby zademonstrować użycie metody . Najpierw tworzy obiekt danych (myDataObject) i przechowuje UnicodeText w nim ciąg z parametrem ustawionym autoConvert na falsewartość . Następnie pobiera formaty skojarzone z danymi przechowywanymi w obiekcie i wyświetla wynik w oknie komunikatu. Jedynym formatem skojarzonym z danymi jest UnicodeText format. W tym przykładzie przyjęto założenie, że utworzono Form nazwę Form1.

private:
   void SetData4()
   {
      // Creates a new data object.
      DataObject^ myDataObject = gcnew DataObject;

      // Adds UnicodeText string to the object, and set the autoConvert
      // parameter to false.
      myDataObject->SetData( DataFormats::UnicodeText, false, "My text String*" );

      // Gets the data format(s) in the data object.
      array<String^>^arrayOfFormats = myDataObject->GetFormats();

      // Stores the results in a string.
      String^ theResult = "The format(s) associated with the data are: \n";
      for ( int i = 0; i < arrayOfFormats->Length; i++ )
         theResult = theResult + arrayOfFormats[ i ], " \n";

      // Show the results in a message box.
      MessageBox::Show( theResult );
   }
       private void SetData4() 
       {
           // Creates a new data object.
           DataObject myDataObject = new DataObject();

           // Adds UnicodeText string to the object, and set the autoConvert 
           // parameter to false.
           myDataObject.SetData(DataFormats.UnicodeText, false, "My text string");

           // Gets the data format(s) in the data object.
           String[] arrayOfFormats = myDataObject.GetFormats();

           // Stores the results in a string.
           string theResult = "The format(s) associated with the data are:" + '\n';
           for(int i=0; i<arrayOfFormats.Length; i++)
               theResult += arrayOfFormats[i] + '\n';
           
           // Show the results in a message box. 
           MessageBox.Show(theResult);
       }
Private Sub SetData4()
    ' Creates a new data object.
    Dim myDataObject As New DataObject()

    ' Adds UnicodeText string to the object, and set the autoConvert
    ' parameter to false.
    myDataObject.SetData(DataFormats.UnicodeText, False, "My text string")

    ' Gets the data format(s) in the data object.
    Dim arrayOfFormats As [String]() = myDataObject.GetFormats()

    ' Stores the results in a string.
    Dim theResult As String = "The format(s) associated with the data are:" + _
            ControlChars.Cr
    Dim i As Integer
    For i = 0 To arrayOfFormats.Length - 1
        theResult += arrayOfFormats(i) + ControlChars.Cr
    Next i
    ' Show the results in a message box. 
    MessageBox.Show(theResult)
End Sub

Uwagi

Jeśli nie znasz formatu aplikacji docelowej, możesz przechowywać dane w wielu formatach przy użyciu tej metody.

Aby zapoznać się z implementacją tej metody, zobacz DataObject.SetData.

Zobacz też

Dotyczy