DataObject.GetData 메서드

정의

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

오버로드

GetData(String, Boolean)

자동 변환 매개 변수를 사용해서 데이터를 해당 형식으로 변환할지 여부를 결정하고 지정된 데이터 형식과 관련된 데이터를 반환합니다.

GetData(String)

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

GetData(Type)

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

GetData(String, Boolean)

자동 변환 매개 변수를 사용해서 데이터를 해당 형식으로 변환할지 여부를 결정하고 지정된 데이터 형식과 관련된 데이터를 반환합니다.

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

매개 변수

format
String

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

autoConvert
Boolean

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

반환

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

구현

예제

다음 코드 예제에서는 매개 변수를 사용하여 autoConvertDataObject저장된 데이터를 검색하여 데이터 형식을 변환할지 여부를 지정합니다.

먼저 텍스트 데이터를 사용하여 새 DataObject 를 만듭니다. 그런 다음, 이 예제에서는 데이터를 검색하여 해당 형식을 문자열로 지정하고 형식 변환을 하지 않습니다. 즉, autoConvert 매개 변수는 입니다 false. 에 문자열 데이터가 DataObject없으므로 이 작업이 실패합니다.

다음으로, 예제에서는 매개 변수가 로 설정된 상태에서 데이터를 다시 autoConvert 검색하려고 시도합니다 true. 이 작업은 성공하고 결과는 에 MessageBox표시됩니다.

이 코드를 실행 하려면 textBox1 만들었습니다.

private:
   void GetMyData3()
   {
      // Creates a new data object using a string and the text format.
      String^ myString = "My new text string";
      DataObject^ myDataObject = gcnew DataObject( DataFormats::Text,myString );
      
      // Prints the string in a text box with autoconvert = false.
      if ( myDataObject->GetData( "System.String", false ) != 0 )
      {
         // Prints the string in a text box.
         textBox1->Text = String::Concat(
            myDataObject->GetData( "System.String", false )->ToString(), "\n" );
      }
      else
      {
         textBox1->Text = "Could not find data of the specified format\n";
      }
      
      // Prints the string in a text box with autoconvert = true.
      textBox1->Text = String::Concat(
            textBox1->Text, myDataObject->GetData( "System.String", true )->ToString() );
   }
private void GetMyData3() {
    // Creates a new data object using a string and the text format.
    string myString = "My new text string";
    DataObject myDataObject = new DataObject(DataFormats.Text, myString);
 
    // Prints the string in a text box with autoconvert = false.
    if(myDataObject.GetData("System.String", false) != null) {
       // Prints the string in a text box.
       textBox1.Text = myDataObject.GetData("System.String", false).ToString() + '\n';
    } else
        {
            textBox1.Text = "Could not find data of the specified format" + '\n';
        }

        // Prints the string in a text box with autoconvert = true.
        textBox1.Text += myDataObject.GetData("System.String", true).ToString();
 }
Private Sub GetMyData3()
    ' Creates a new data object using a string and the text format.
    Dim myString As String = "My new text string"
    Dim myDataObject As New DataObject(DataFormats.Text, myString)
    
    ' Prints the string in a text box with autoconvert = false.
    If (myDataObject.GetData("System.String", False) IsNot Nothing) Then
        ' Prints the string in a text box.
        textBox1.Text = myDataObject.GetData("System.String", False).ToString() & ControlChars.Cr
    Else
        textBox1.Text = "Could not find data of the specified format" & ControlChars.Cr
    End If 
    ' Prints the string in a text box with autoconvert = true.
    textBox1.Text += myDataObject.GetData("System.String", True).ToString()
End Sub

설명

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

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

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

참고

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

formatHtml,이 메서드는.NET 4.5 이상을 대상으로 하는 애플리케이션에서 u t F-8로 인코딩된 문자열을 반환 합니다. 및 ANSI로 인코딩된 문자열 애플리케이션에서.NET 4.0 또는 낮은 대상으로 하는 합니다.

추가 정보

적용 대상

GetData(String)

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

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

매개 변수

format
String

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

반환

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

구현

예제

다음 코드 예제에서는 에 DataObject저장된 데이터를 검색합니다. 먼저 텍스트 데이터를 사용하여 새 DataObject 를 만듭니다. 그런 다음 데이터를 검색하여 해당 형식을 문자열로 지정하고 텍스트 상자에 표시합니다.

이 코드를 실행 하려면 textBox1 만들었습니다.

private:
   void AddMyData3()
   {
      // Creates a component to store in the data object.
      Component^ myComponent = gcnew Component;
      
      // Creates a new data object.
      DataObject^ myDataObject = gcnew DataObject;
      
      // Adds the component to the DataObject.
      myDataObject->SetData( myComponent );
      
      // Prints whether data of the specified type is in the DataObject.
      Type^ myType = myComponent->GetType();
      if ( myDataObject->GetDataPresent( myType ) )
      {
         textBox1->Text = String::Concat( "Data of type ", myType,
            " is present in the DataObject" );
      }
      else
      {
         textBox1->Text = String::Concat( "Data of type ", myType,
            " is not present in the DataObject" );
      }
   }
private void AddMyData3() {
    // Creates a component to store in the data object.
    Component myComponent = new Component();
 
    // Creates a new data object.
    DataObject myDataObject = new DataObject();
 
    // Adds the component to the DataObject.
    myDataObject.SetData(myComponent);
 
    // Prints whether data of the specified type is in the DataObject.
    Type myType = myComponent.GetType();
    if(myDataObject.GetDataPresent(myType))
       textBox1.Text = "Data of type " + myType.ToString() + 
       " is present in the DataObject";
    else
       textBox1.Text = "Data of type " + myType.ToString() +
       " is not present in the DataObject";
 }
Private Sub AddMyData3()
    ' Creates a component to store in the data object.
    Dim myComponent As New Component()
    
    ' Creates a new data object.
    Dim myDataObject As New DataObject()
    
    ' Adds the component to the DataObject.
    myDataObject.SetData(myComponent)
    
    ' Prints whether data of the specified type is in the DataObject.
    Dim myType As Type = myComponent.GetType()
    If myDataObject.GetDataPresent(myType) Then
        textBox1.Text = "Data of type " & myType.ToString() & _
            " is present in the DataObject"
    Else
        textBox1.Text = "Data of type " & myType.ToString() & _
            " is not present in the DataObject"
    End If
End Sub

설명

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

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

참고

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

formatHtml,이 메서드는.NET 4.5 이상을 대상으로 하는 애플리케이션에서 u t F-8로 인코딩된 문자열을 반환 합니다. 및 ANSI로 인코딩된 문자열 애플리케이션에서.NET 4.0 또는 낮은 대상으로 하는 합니다.

추가 정보

적용 대상

GetData(Type)

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

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

매개 변수

format
Type

검색할 데이터의 형식을 나타내는 Type입니다.

반환

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

구현

예제

다음 코드 예제에서는 에 DataObject저장된 데이터를 검색합니다. 먼저 구성 요소를 사용하여 새 DataObject 를 만듭니다. 그런 다음, 해당 형식을 지정하여 데이터를 검색합니다. 검색된 데이터의 형식이 텍스트 상자에 표시됩니다.

이 코드를 실행 하려면 textBox1 만들었습니다.

private:
   void GetMyData()
   {
      // Creates a component to store in the data object.
      Component^ myComponent = gcnew Component;
      
      // Creates a new data object and assigns it the component.
      DataObject^ myDataObject = gcnew DataObject( myComponent );
      
      // Creates a type 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 )
      {
         textBox1->Text = String::Format( "The data type stored in the DataObject is: {0}",
            myObject->GetType()->Name );
      }
      else
      {
         textBox1->Text = "Data of the specified type was not stored in the DataObject.";
      }
   }
private void GetMyData() {
    // Creates a component to store in the data object.
    Component myComponent = new Component();
 
    // Creates a new data object and assigns it the component.
    DataObject myDataObject = new DataObject(myComponent);
 
    // Creates a type 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)
       textBox1.Text = "The data type stored in the DataObject is: " +
       myObject.GetType().Name;
    else
       textBox1.Text = "Data of the specified type was not stored " +
       "in the DataObject.";
 }
Private Sub GetMyData()
    ' Creates a component to store in the data object.
    Dim myComponent As New Component()
    
    ' Creates a new data object and assigns it the component.
    Dim myDataObject As New DataObject(myComponent)
    
    ' Creates a type 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
        textBox1.Text = "The data type stored in the DataObject is: " & myObject.GetType().Name
    Else
        textBox1.Text = "Data of the specified type was not stored " & "in the DataObject."
    End If
End Sub

설명

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

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

참고

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

추가 정보

적용 대상