DataObject.GetData 메서드

정의

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

오버로드

Name Description
GetData(String)
사용되지 않음.

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

GetData(Type)
사용되지 않음.

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

GetData(String, Boolean)
사용되지 않음.

자동화된 변환 매개 변수를 사용하여 지정된 데이터 형식과 연결된 데이터를 반환하여 데이터를 형식으로 변환할지 여부를 결정합니다.

GetData(String)

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

주의

DataObject.GetData methods are obsolete. Use the corresponding DataObject.TryGetData<T> instead.

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

public:
 virtual System::Object ^ GetData(System::String ^ format);
public virtual object GetData(string format);
[System.Obsolete("`DataObject.GetData` methods are obsolete. Use the corresponding `DataObject.TryGetData<T>` instead.", false, DiagnosticId="WFDEV005", UrlFormat="https://aka.ms/winforms-warnings/{0}")]
public virtual object? GetData(string format);
public virtual object? GetData(string format);
abstract member GetData : string -> obj
override this.GetData : string -> obj
[<System.Obsolete("`DataObject.GetData` methods are obsolete. Use the corresponding `DataObject.TryGetData<T>` instead.", false, DiagnosticId="WFDEV005", UrlFormat="https://aka.ms/winforms-warnings/{0}")>]
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.

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

메모

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

format Html 이 메서드는 .NET 4.5 이상을 대상으로 하는 애플리케이션에서 UTF-8로 인코딩된 문자열을 반환하고 4.0 이하를 대상으로 하는 애플리케이션에서 ANSI로 인코딩된 문자열을 .NET 반환합니다.

추가 정보

적용 대상

GetData(Type)

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

주의

DataObject.GetData methods are obsolete. Use the corresponding DataObject.TryGetData&lt;T&gt; instead.

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

public:
 virtual System::Object ^ GetData(Type ^ format);
public virtual object GetData(Type format);
[System.Obsolete("`DataObject.GetData` methods are obsolete. Use the corresponding `DataObject.TryGetData<T>` instead.", false, DiagnosticId="WFDEV005", UrlFormat="https://aka.ms/winforms-warnings/{0}")]
public virtual object? GetData(Type format);
public virtual object? GetData(Type format);
abstract member GetData : Type -> obj
override this.GetData : Type -> obj
[<System.Obsolete("`DataObject.GetData` methods are obsolete. Use the corresponding `DataObject.TryGetData<T>` instead.", false, DiagnosticId="WFDEV005", UrlFormat="https://aka.ms/winforms-warnings/{0}")>]
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.

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

메모

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

추가 정보

적용 대상

GetData(String, Boolean)

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

주의

DataObject.GetData methods are obsolete. Use the corresponding DataObject.TryGetData&lt;T&gt; instead.

자동화된 변환 매개 변수를 사용하여 지정된 데이터 형식과 연결된 데이터를 반환하여 데이터를 형식으로 변환할지 여부를 결정합니다.

public:
 virtual System::Object ^ GetData(System::String ^ format, bool autoConvert);
public virtual object GetData(string format, bool autoConvert);
[System.Obsolete("`DataObject.GetData` methods are obsolete. Use the corresponding `DataObject.TryGetData<T>` instead.", false, DiagnosticId="WFDEV005", UrlFormat="https://aka.ms/winforms-warnings/{0}")]
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
[<System.Obsolete("`DataObject.GetData` methods are obsolete. Use the corresponding `DataObject.TryGetData<T>` instead.", false, DiagnosticId="WFDEV005", UrlFormat="https://aka.ms/winforms-warnings/{0}")>]
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.

구현

특성

예제

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

첫째, 텍스트 데이터를 사용하여 새 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

설명

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

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

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

메모

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

format Html 이 메서드는 .NET 4.5 이상을 대상으로 하는 애플리케이션에서 UTF-8로 인코딩된 문자열을 반환하고 4.0 이하를 대상으로 하는 애플리케이션에서 ANSI로 인코딩된 문자열을 .NET 반환합니다.

추가 정보

적용 대상