IDataObject.GetDataPresent 메서드

정의

이 인스턴스에 저장된 데이터가 지정된 형식과 관련되어 있는지 여부를 확인합니다.

오버로드

GetDataPresent(String)

이 인스턴스에 저장된 데이터가 지정된 형식과 관련되어 있거나 해당 형식으로 변환될 수 있는지 여부를 확인합니다.

GetDataPresent(Type)

이 인스턴스에 저장된 데이터가 지정된 형식과 관련되어 있거나 해당 형식으로 변환될 수 있는지 여부를 확인합니다.

GetDataPresent(String, Boolean)

부울 값을 통해 데이터를 해당 형식으로 변환할지 여부를 확인하여 이 인스턴스에 저장된 데이터가 지정한 형식과 관련되어 있는지 여부를 확인합니다.

GetDataPresent(String)

이 인스턴스에 저장된 데이터가 지정된 형식과 관련되어 있거나 해당 형식으로 변환될 수 있는지 여부를 확인합니다.

public:
 bool GetDataPresent(System::String ^ format);
public bool GetDataPresent (string format);
abstract member GetDataPresent : string -> bool
Public Function GetDataPresent (format As String) As Boolean

매개 변수

format
String

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

반환

Boolean

이 인스턴스에 저장된 데이터가 지정된 형식과 관련되어 있거나 해당 형식으로 변환될 수 있으면 true이고, 그렇지 않으면 false입니다.

예제

이 예제에서는 구현하는 클래스를 IDataObject사용하여 DataObject 메서드의 사용을 보여 줍니다GetDataPresent. 먼저 문자열 및 형식을 사용하여 데이터 개체를 Text 만듭니다. 그런 다음 데이터가 형식으로 있는지 Text 확인하고 메시지 상자에 결과를 표시합니다. 이 예제에서는 명명Form1된 이름을 만들었다고 가정합니다Form.

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

      // Checks whether the data is present in the Text format and displays the result.
      if ( myDataObject->GetDataPresent( DataFormats::Text ) )
            MessageBox::Show( "The stored data is in the Text format.", "Test Result" );
      else
            MessageBox::Show( "The stored data is not in the Text format.", "Test Result" );
   }
       private void TestDataObject() 
       {
           // Creates a new data object using a string and the Text format.
           string myString = "Hello World!";
           DataObject myDataObject = new DataObject(DataFormats.Text, myString);

           // Checks whether the data is present in the Text format and displays the result.
           if (myDataObject.GetDataPresent(DataFormats.Text))
               MessageBox.Show("The stored data is in the Text format." , "Test Result");
           else
               MessageBox.Show("The stored data is not in the Text format.", "Test Result");
       }
Private Sub TestDataObject()
    ' Creates a new data object using a string and the Text format.
    Dim myString As New String("Hello World!")
    Dim myDataObject As New DataObject(DataFormats.Text, myString)

    ' Checks whether the data is present in the Text format and displays the result.
    If (myDataObject.GetDataPresent(DataFormats.Text)) Then
        MessageBox.Show("The stored data is in the Text format.", "Test Result")
    Else
        MessageBox.Show("The stored data is not in the Text format.", "Test Result")
    End If
End Sub

설명

호출하기 전에 이 메서드를 호출GetData하여 형식이 이 DataObject 메서드에 있는지 여부를 확인합니다. 이 인스턴스에서 사용할 수 있는 형식을 호출 GetFormats 합니다.

참고

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

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

추가 정보

적용 대상

GetDataPresent(Type)

이 인스턴스에 저장된 데이터가 지정된 형식과 관련되어 있거나 해당 형식으로 변환될 수 있는지 여부를 확인합니다.

public:
 bool GetDataPresent(Type ^ format);
public bool GetDataPresent (Type format);
abstract member GetDataPresent : Type -> bool
Public Function GetDataPresent (format As Type) As Boolean

매개 변수

format
Type

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

반환

Boolean

이 인스턴스에 저장된 데이터가 지정된 형식과 관련되어 있거나 해당 형식으로 변환될 수 있으면 true이고, 그렇지 않으면 false입니다.

예제

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

private:
   void GetDataPresent2()
   {
      // 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();

      // Checks whether the specified data type exists in the object.
      if ( myDataObject->GetDataPresent( myType ) )
      {
         MessageBox::Show( "The specified data is stored in the data object." );

         // Displays the type of data.
         textBox1->Text = "The data type is " + myDataObject->GetData( myType )->GetType()->Name + ".";
      }
      else
            MessageBox::Show( "The specified data is not stored in the data object." );
   }
       private void GetDataPresent2() 
       {
           // 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();

           // Checks whether the specified data type exists in the object.
           if (myDataObject.GetDataPresent(myType))
           {
               MessageBox.Show("The specified data is stored in the data object.");
               // Displays the type of data.
               textBox1.Text = "The data type is " + myDataObject.GetData(myType).GetType().Name + ".";
           }
           else
           {
               MessageBox.Show("The specified data is not stored in the data object.");
           }
       }
Private Sub GetDataPresent2()
    ' Creates a component to store in the data object.
    Dim myComponent As New System.ComponentModel.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()

    ' Checks whether the specified data type exists in the object.
    If myDataObject.GetDataPresent(myType) Then
        MessageBox.Show("The specified data is stored in the data object.")
        ' Displays the type of data.
        TextBox1.Text = "The data type is " & myDataObject.GetData(myType).GetType().Name & "."
    Else
        MessageBox.Show("The specified data is not stored in the data object.")
    End If
End Sub

설명

호출하기 전에 이 메서드를 호출GetData하여 형식이 이 DataObject 메서드에 있는지 여부를 확인합니다. 이 인스턴스에서 사용할 수 있는 형식을 호출 GetFormats 합니다.

참고

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

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

추가 정보

적용 대상

GetDataPresent(String, Boolean)

부울 값을 통해 데이터를 해당 형식으로 변환할지 여부를 확인하여 이 인스턴스에 저장된 데이터가 지정한 형식과 관련되어 있는지 여부를 확인합니다.

public:
 bool GetDataPresent(System::String ^ format, bool autoConvert);
public bool GetDataPresent (string format, bool autoConvert);
abstract member GetDataPresent : string * bool -> bool
Public Function GetDataPresent (format As String, autoConvert As Boolean) As Boolean

매개 변수

format
String

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

autoConvert
Boolean

이 인스턴스에 저장된 데이터를 지정된 형식으로 변환할 수 있는지 여부를 확인하려면 true이고 데이터 형식이 지정된 형식인지 여부를 확인하려면 false입니다.

반환

Boolean

데이터가 지정된 형식이거나 지정된 형식으로 변환할 수 있으면 true이고, 그렇지 않으면 false입니다.

예제

이 예제에서는 구현하는 클래스를 IDataObject사용하여 DataObject 메서드의 사용을 보여 줍니다GetDataPresent. 먼저 문자열 및 형식을 사용하여 데이터 개체(myDataObject)를 Text 만듭니다. 그런 다음, 매개 변수가 .로 설정된 형식과 Text 연결된 데이터에 대해 개체를 autoConvert 쿼리합니다 false. 이 평가판이 실패하면 결과는 "메시지 #1"이라는 레이블이 지정된 메시지 상자에 표시됩니다. 두 번째 평가판에서는 매개 변수를 autoConvert .로 true설정합니다. 이 평가판이 성공하면 결과는 "메시지 #2"라는 레이블이 지정된 메시지 상자에 표시됩니다. 이 예제에서는 명명Form1된 이름을 만들었다고 가정합니다Form.

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

      // Checks whether the string can be displayed with autoConvert equal to false.
      if ( myDataObject->GetDataPresent( "System::String", false ) )
            MessageBox::Show( myDataObject->GetData( "System::String", false )->ToString(), "Message #1" );
      else
            MessageBox::Show( "Cannot convert data to the specified format with autoConvert set to false.", "Message #1" );

      // Displays the string with autoConvert equal to true.
      MessageBox::Show( "Now that autoConvert is true, you can convert " + myDataObject->GetData( "System::String", true ) + " to string format.", "Message #2" );
   }
       private void GetDataPresent3() 
       {
           // Creates a new data object using a string and the Text format.
           DataObject myDataObject = new DataObject(DataFormats.Text, "My String");

           // Checks whether the string can be displayed with autoConvert equal to false.
           if(myDataObject.GetDataPresent("System.String", false)) 
               MessageBox.Show(myDataObject.GetData("System.String", false).ToString(), "Message #1");
           else
               MessageBox.Show("Cannot convert data to the specified format with autoConvert set to false.", "Message #1");

           // Displays the string with autoConvert equal to true.
           MessageBox.Show("Now that autoConvert is true, you can convert " + 
               myDataObject.GetData("System.String", true).ToString() + " to string format.","Message #2");
       }
Private Sub GetDataPresent3()
    ' Creates a new data object using a string and the Text format.
    Dim myDataObject As New DataObject(DataFormats.Text, "My String")

    ' Checks whether the string can be displayed with autoConvert equal to false.
    If myDataObject.GetDataPresent("System.String", False) Then
        MessageBox.Show(myDataObject.GetData("System.String", False).ToString() + ".", "Message #1")
    Else
        MessageBox.Show("Cannot convert data to the specified format with autoConvert set to false.", "Message #1")
    End If
    ' Displays the string with autoConvert equal to true.
    MessageBox.Show(("Now that autoConvert is true, you can convert " + myDataObject.GetData("System.String", _
         True).ToString() + " to string format."), "Message #2")

End Sub

설명

호출하기 전에 이 메서드를 호출GetData하여 형식이 이 DataObject 메서드에 있는지 여부를 확인합니다. 이 인스턴스에서 사용할 수 있는 형식을 호출 GetFormats 합니다.

이 메서드는 다음과 같은 경우를 반환합니다 true .

  • autoConvert 매개 변수가 true 있고 데이터는 적절한 형식으로 변환할 수 있는 형식입니다.

  • autoConvert 매개 변수가 false 있고 데이터가 적절한 형식입니다.

이 메서드는 다음과 같은 경우를 반환합니다 false .

  • autoConvert 매개 변수이며 true 이 메서드는 지정된 형식의 데이터를 찾을 수 없으며 데이터를 지정된 형식으로 변환할 수 없거나 데이터가 false로 설정된 상태로 autoConvert 저장되었습니다.

  • The autoConvert parameter is false, and data does not exist in this instance in the specified format.

참고

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

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

추가 정보

적용 대상