IDataObject.SetData 메서드

정의

지정된 데이터 및 관련된 형식을 이 인스턴스에 저장합니다.

오버로드

SetData(Object)

지정된 데이터를 이 형식에 대한 데이터 클래스를 사용하여 이 인스턴스에 저장합니다.

SetData(String, Object)

지정된 데이터 및 관련된 형식을 이 인스턴스에 저장합니다.

SetData(Type, Object)

지정된 데이터 및 관련된 클래스 형식을 이 인스턴스에 저장합니다.

SetData(String, Boolean, Object)

부울 값을 통해 데이터를 다른 형식으로 변환할 수 있는지 여부를 지정하여 선택한 데이터 및 관련된 형식을 이 인스턴스에 저장합니다.

SetData(Object)

지정된 데이터를 이 형식에 대한 데이터 클래스를 사용하여 이 인스턴스에 저장합니다.

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)

매개 변수

data
Object

저장할 데이터입니다.

예제

이 예제에서는 구현하는 클래스를 IDataObject사용하여 DataObject 메서드의 사용을 보여 줍니다SetData. 먼저 구성 요소(myComponent)를 만들고 데이터 개체(myDataObject)에 저장합니다. 그런 다음, 지정된 데이터가 데이터 개체에 저장되어 있는지 여부를 확인하고 결과를 메시지 상자에 표시합니다. 이 예제에서는 명명Form1된 이름을 만들었다고 가정합니다Form.

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

설명

형식은 데이터 클래스에서 파생됩니다.

이 메서드를 사용하여 저장된 데이터는 검색할 때 호환되는 형식으로 변환할 수 있습니다.

이 메서드를 구현 하는 것을 참조 하세요. DataObject.SetData합니다.

추가 정보

적용 대상

SetData(String, Object)

지정된 데이터 및 관련된 형식을 이 인스턴스에 저장합니다.

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)

매개 변수

format
String

데이터와 관련된 형식입니다. 미리 정의된 형식에 대한 자세한 내용은 DataFormats를 참조하십시오.

data
Object

저장할 데이터입니다.

예제

이 예제에서는 구현하는 클래스를 IDataObject사용하여 DataObject 메서드의 사용을 보여 줍니다SetData. 먼저 데이터 개체(myDataObject)를 만들고 형식을 지정하는 문자열을 개체에 UnicodeText 저장합니다. 그런 다음, 형식을 지정하는 개체에 저장된 데이터를 검색하여 Text 데이터가 형식으로 변환되도록 합니다 Text . 결과는 메시지 상자에 표시됩니다. 이 예제에서는 명명Form1된 이름을 만들었다고 가정합니다Form.

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

설명

대상 애플리케이션의 형식을 모르는 경우이 메서드를 사용 하 여 여러 형식의 데이터를 저장할 수 있습니다.

이 메서드를 사용하여 저장된 데이터는 검색할 때 호환되는 형식으로 변환할 수 있습니다.

이 메서드를 구현 하는 것을 참조 하세요. DataObject.SetData합니다.

추가 정보

적용 대상

SetData(Type, Object)

지정된 데이터 및 관련된 클래스 형식을 이 인스턴스에 저장합니다.

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)

매개 변수

format
Type

데이터와 관련된 형식을 나타내는 Type입니다. 미리 정의된 형식에 대한 자세한 내용은 DataFormats를 참조하십시오.

data
Object

저장할 데이터입니다.

예제

이 예제에서는 구현하는 클래스를 IDataObject사용하여 DataObject 메서드의 사용을 보여 줍니다SetData. 먼저 구성 요소(myComponent)를 만들고 데이터 형식을 지정하는 데 사용하여 데이터 개체()myDataObjectmyType 저장합니다. 그런 다음 지정된 형식의 데이터가 개체에 저장되어 있는지 확인하고 결과를 메시지 상자에 표시합니다. 이 예제에서는 명명Form1된 이름을 만들었다고 가정합니다Form.

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

설명

대상 애플리케이션의 형식을 모르는 경우이 메서드를 사용 하 여 여러 형식의 데이터를 저장할 수 있습니다.

이 메서드를 사용하여 저장된 데이터는 검색할 때 호환되는 형식으로 변환할 수 있습니다.

이 메서드를 구현 하는 것을 참조 하세요. DataObject.SetData합니다.

추가 정보

적용 대상

SetData(String, Boolean, Object)

부울 값을 통해 데이터를 다른 형식으로 변환할 수 있는지 여부를 지정하여 선택한 데이터 및 관련된 형식을 이 인스턴스에 저장합니다.

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)

매개 변수

format
String

데이터와 관련된 형식입니다. 미리 정의된 형식에 대한 자세한 내용은 DataFormats를 참조하십시오.

autoConvert
Boolean

데이터를 다른 형식으로 변환할 수 있도록 하려면 true이고, 그렇지 않으면 false입니다.

data
Object

저장할 데이터입니다.

예제

이 예제에서는 구현하는 클래스를 IDataObject사용하여 DataObject 메서드의 사용을 보여 줍니다SetData. 먼저 데이터 개체(myDataObject)를 만들고 매개 변수falseUnicodeText 사용하여 문자열을 autoConvert 저장합니다. 그런 다음 개체에 저장된 데이터와 연결된 형식을 검색하고 결과를 메시지 상자에 표시합니다. 데이터와 연결된 유일한 형식은 형식입니다 UnicodeText . 이 예제에서는 명명Form1된 이름을 만들었다고 가정합니다Form.

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

설명

대상 애플리케이션의 형식을 모르는 경우이 메서드를 사용 하 여 여러 형식의 데이터를 저장할 수 있습니다.

이 메서드를 구현 하는 것을 참조 하세요. DataObject.SetData합니다.

추가 정보

적용 대상