IDataObject.GetData 메서드

정의

지정된 데이터 형식과 관련된 데이터를 검색합니다.

오버로드

GetData(String)

지정된 데이터 형식과 관련된 데이터를 검색합니다.

GetData(Type)

지정된 클래스 형식과 관련된 데이터를 검색합니다.

GetData(String, Boolean)

부울을 통해 데이터를 지정된 데이터 형식으로 변환할지 여부를 확인하여 해당 데이터 형식과 관련된 데이터를 검색합니다.

GetData(String)

지정된 데이터 형식과 관련된 데이터를 검색합니다.

public:
 System::Object ^ GetData(System::String ^ format);
public object GetData (string format);
public object? GetData (string format);
abstract member GetData : string -> obj
Public Function GetData (format As String) As Object

매개 변수

format
String

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

반환

Object

지정된 형식과 관련된 데이터 또는 null입니다.

예제

이 예제에서는 메서드의 DataObject 사용을 보여 주는 구현 IDataObject, 하는 클래스를 GetData 사용 합니다. 이 메서드는 형식과 연결된 Text 저장된 데이터를 myDataObject검색하는 데 사용됩니다. 이 예제에서는 명명된 이름과 이름을 Form1 textBox1이미 만들었다고 Form 가정합니다TextBox.

private:
   void GetData1()
   {
      // Creates a new data object using a string and the text format.
      String^ myString = "My text string";
      DataObject^ myDataObject = gcnew DataObject( DataFormats::Text,myString );

      // Displays the string in a text box.
      textBox1->Text = myDataObject->GetData( DataFormats::Text )->ToString();
   }
private void GetData1() 
{
    // Creates a new data object using a string and the text format.
    string myString = "My text string";
    DataObject myDataObject = new DataObject(DataFormats.Text, myString);

    // Displays the string in a text box.
    textBox1.Text = myDataObject.GetData(DataFormats.Text).ToString();
}
Private Sub GetData1()
    ' Creates a new data object using a string and the text format.
    Dim myString As String = "My text string"
    Dim myDataObject As New DataObject(DataFormats.Text, myString)

    ' Displays the string in a text box.
    textBox1.Text = myDataObject.GetData(DataFormats.Text).ToString()
End Sub

설명

이 메서드가 지정된 형식의 데이터를 찾을 수 없는 경우 데이터를 형식으로 변환하려고 시도합니다. 데이터를 지정된 형식으로 변환할 수 없으면 이 메서드가 반환됩니다 null.

데이터가 형식과 연결되어 있는지 또는 형식으로 변환될 수 있는지 확인하려면 호출GetData하기 전에 호출 GetDataPresent 합니다. 이 인스턴스에 저장된 데이터에 대한 유효한 형식 목록을 호출 GetFormats 합니다.

참고

변환이 허용되도록 지정하고 요청된 형식이 저장된 형식과 호환되는 경우 데이터를 다른 형식으로 변환할 수 있습니다. 예를 들어 유니코드로 저장된 데이터를 텍스트로 변환할 수 있습니다.

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

추가 정보

적용 대상

GetData(Type)

지정된 클래스 형식과 관련된 데이터를 검색합니다.

public:
 System::Object ^ GetData(Type ^ format);
public object GetData (Type format);
public object? GetData (Type format);
abstract member GetData : Type -> obj
Public Function GetData (format As Type) As Object

매개 변수

format
Type

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

반환

Object

지정된 형식과 관련된 데이터 또는 null입니다.

예제

이 예제에서는 구현하는 클래스를 IDataObject사용하여 DataObject 메서드의 사용을 보여 줍니다GetData. 이 메서드는 특정 형식myType과 연결된 저장된 데이터를 myObject검색하는 데 사용됩니다. 검색된 데이터의 형식이 메시지 상자에 표시됩니다. 이 예제에서는 이미 명명Form1된 이름을 만들었다고 가정합니다Form.

private:
   void GetData2()
   {
      // Creates a component.
      Component^ myComponent = gcnew Component;

      // Creates a data object, and assigns it the component.
      DataObject^ myDataObject = gcnew DataObject( myComponent );

      // Creates a type, myType, to store the type of data.
      Type^ myType = myComponent->GetType();

      // Retrieves the data using myType to represent its type.
      Object^ myObject = myDataObject->GetData( myType );
      if ( myObject != nullptr )
            MessageBox::Show( "The data type stored in the data object is " +
                  myObject->GetType()->Name + "." );
      else
            MessageBox::Show( "Data of the specified type was not stored in the data object." );
   }
       private void GetData2() 
       {
           // Creates a component.
           Component myComponent = new Component();

           // Creates a data object, and assigns it the component.
           DataObject myDataObject = new DataObject(myComponent);

           // Creates a type, myType, to store the type of data.
           Type myType = myComponent.GetType();

           // Retrieves the data using myType to represent its type.
           Object myObject = myDataObject.GetData(myType);
           if(myObject != null)
               MessageBox.Show("The data type stored in the data object is " +
                   myObject.GetType().Name + ".");
           else
               MessageBox.Show("Data of the specified type was not stored " +
                   "in the data object.");
       }
Private Sub GetData2()
    ' Creates a component.
    Dim myComponent As New System.ComponentModel.Component()

    ' Creates a data object, and assigns it the component.
    Dim myDataObject As New DataObject(myComponent)

    ' Creates a type, myType, to store the type of data.
    Dim myType As Type = myComponent.GetType()

    ' Retrieves the data using myType to represent its type.
    Dim myObject As [Object] = myDataObject.GetData(myType)
    If (myObject IsNot Nothing) Then
        MessageBox.Show("The data type stored in the data object is " + myObject.GetType().Name + ".")
    Else
        MessageBox.Show("Data of the specified type was not stored " + "in the data object.")
    End If
End Sub

설명

이 메서드가 지정된 형식의 데이터를 찾을 수 없는 경우 데이터를 형식으로 변환하려고 시도합니다. 데이터를 지정된 형식으로 변환할 수 없으면 이 메서드가 반환됩니다 null.

데이터가 형식과 연결되어 있는지 또는 형식으로 변환될 수 있는지 확인하려면 호출GetData하기 전에 호출 GetDataPresent 합니다. 이 인스턴스에 저장된 데이터에 대한 유효한 형식 목록을 호출 GetFormats 합니다.

참고

변환이 허용되도록 지정하고 요청된 형식이 저장된 형식과 호환되는 경우 데이터를 다른 형식으로 변환할 수 있습니다. 예를 들어 유니코드로 저장된 데이터를 텍스트로 변환할 수 있습니다.

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

추가 정보

적용 대상

GetData(String, Boolean)

부울을 통해 데이터를 지정된 데이터 형식으로 변환할지 여부를 확인하여 해당 데이터 형식과 관련된 데이터를 검색합니다.

public:
 System::Object ^ GetData(System::String ^ format, bool autoConvert);
public object GetData (string format, bool autoConvert);
public object? GetData (string format, bool autoConvert);
abstract member GetData : string * bool -> obj
Public Function GetData (format As String, autoConvert As Boolean) As Object

매개 변수

format
String

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

autoConvert
Boolean

데이터를 지정된 형식으로 변환하려면 true이고, 그렇지 않으면 false입니다.

반환

Object

지정된 형식과 관련된 데이터 또는 null입니다.

예제

이 예제에서는 구현하는 클래스를 IDataObject사용하여 DataObject 메서드의 사용을 보여 줍니다GetData. 이 예제에서는 매개 변수를 사용하여 autoConvert 데이터 형식을 변환할지 여부를 지정하여 저장된 DataObject데이터를 검색합니다. myDataObject 먼저 텍스트 데이터를 사용하여 만듭니다. 그런 다음, 두 번 시도하여 데이터를 검색합니다. 첫 번째 평가판에서는 해당 형식을 문자열로 지정하고 매개 변수falseautoConvert .로 설정합니다. 이 평가판이 실패하면 결과는 "메시지 #1"이라는 레이블이 지정된 메시지 상자에 표시됩니다. 두 번째 평가판에서는 매개 변수가 로 autoConvert 설정된 동일한 데이터를 검색합니다 true. 이 평가판이 성공하면 결과는 "메시지 #2"라는 레이블이 지정된 메시지 상자에 표시됩니다. 이 예제에서는 명명Form1된 이름을 만들었다고 가정합니다Form.

private:
   void GetData3()
   {
      // Creates a new data object using a text string.
      String^ myString = "Hello World!";
      DataObject^ myDataObject = gcnew DataObject( DataFormats::Text,myString );

      // Displays the string with autoConvert equal to false.
      if ( myDataObject->GetData( "System::String", false ) != nullptr )
      {
         // Displays the string in a message box.
         MessageBox::Show( myDataObject->GetData( "System::String", false ) + ".", "Message #1" );
      }
      else
            MessageBox::Show( "Could not find data of the specified format.", "Message #1" );

      // Displays a not found message in a message box.
      // Displays the string in a text box with autoConvert equal to true.
      String^ myData = "The data is " + myDataObject->GetData( "System::String", true ) + ".";
      MessageBox::Show( myData, "Message #2" );
   }
       private void GetData3() 
       {
           // Creates a new data object using a text string.
           string myString = "Hello World!";
           DataObject myDataObject = new DataObject(DataFormats.Text, myString);

           // Displays the string with autoConvert equal to false.
           if (myDataObject.GetData("System.String", false) != null) 
           {
               // Displays the string in a message box.
               MessageBox.Show(myDataObject.GetData("System.String", false).ToString() + ".", "Message #1");
           } 
           else
           {
               // Displays a not found message in a message box.
               MessageBox.Show("Could not find data of the specified format.", "Message #1");
           }

           // Displays the string in a text box with autoConvert equal to true.
           string myData = "The data is " + myDataObject.GetData("System.String", true).ToString() +".";
           MessageBox.Show(myData,"Message #2");
       }
Private Sub GetData3()
    ' Creates a new data object using a text string.
    Dim myString As String = "Hello World!"
    Dim myDataObject As New DataObject(DataFormats.Text, myString)

    ' Displays the string with autoConvert equal to false.
    If (myDataObject.GetData("System.String", False) IsNot Nothing) Then
        ' Displays the string in a message box.
        MessageBox.Show(myDataObject.GetData("System.String", False).ToString() + ".", "Message #1")
        ' Displays a not found message in a message box.
    Else
        MessageBox.Show("Could not find data of the specified format.", "Message #1")
    End If

    ' Displays the string in a text box with autoConvert equal to true.
    Dim myData As String = "The data is " + myDataObject.GetData("System.String", True).ToString()
    MessageBox.Show(myData, "Message #2")
End Sub

설명

매개 변수가 autoConvert 있고 true 이 메서드가 지정된 형식의 데이터를 찾을 수 없는 경우 데이터를 형식으로 변환하려고 시도합니다. 데이터를 지정된 형식으로 변환할 수 없거나 매개 변수가 설정된 false상태에서 autoConvert 데이터를 저장한 경우 이 메서드는 반환합니다null.

매개 변수인 autoConvert 경우 이 메서드는 false지정된 형식의 데이터를 반환하거나 null 이 형식의 데이터를 찾을 수 없는 경우 반환합니다.

데이터가 형식과 연결되어 있는지 또는 형식으로 변환될 수 있는지 확인하려면 호출GetData하기 전에 호출 GetDataPresent 합니다. 이 인스턴스에 저장된 데이터에 대한 유효한 형식 목록을 호출 GetFormats 합니다.

참고

변환이 허용되도록 지정하고 요청된 형식이 저장된 형식과 호환되는 경우 데이터를 다른 형식으로 변환할 수 있습니다. 예를 들어 유니코드로 저장된 데이터를 텍스트로 변환할 수 있습니다.

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

추가 정보

적용 대상