次の方法で共有


IDataObject.GetDataPresent メソッド (Type)

インスタンスに格納されているデータが、指定した形式と関連付けられているかどうかや、その形式に変換できるかどうかを確認します。

Function GetDataPresent( _
   ByVal format As Type _) As Boolean
[C#]
bool GetDataPresent(
   Typeformat);
[C++]
bool GetDataPresent(
   Type* format);
[JScript]
function GetDataPresent(
   format : Type) : Boolean;

パラメータ

  • format
    確認対象となる形式を表す Type 。定義済みの形式については、 DataFormats のトピックを参照してください。

戻り値

インスタンスに格納されているデータが、指定されている形式に関連付けられている場合や、その形式に変換できる場合は true 。それ以外の場合は false

解説

DataObject に形式が格納されているかどうかを確認するには、 GetData を呼び出す前に、このメソッドを呼び出します。インスタンスで使用できる形式を取得するには、 GetFormats を呼び出します。

メモ   形式変換を有効にしてデータが格納されている場合、要求した形式が、格納されている形式と互換性があれば、そのデータを別の形式に変換できます。たとえば、Unicode として格納されたデータをテキストに変換できます。

このメソッドの実装については、 DataObject.GetDataPresent のトピックを参照してください。

使用例

[Visual Basic, C#, C++] この例では、 IDataObject を実装する DataObject クラスを使用して GetDataPresent メソッドの使用法を示します。最初に、コンポーネント (myComponent) を作成し、データ オブジェクト (myDataObject) に格納します。次に、指定したデータが myDataObject に格納されているかどうかを確認します。テストの評価が true の場合は、結果をメッセージ ボックスに表示し、データ型をテキスト ボックスに表示します。この例は、 Form1 という名前の FormtextBox1 という名前の TextBox が既に作成されていることを前提にしています。

 
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 'GetDataPresent2

[C#] 
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.");
}

[C++] 
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(S"The specified data is stored in the data object.");
            // Displays the type of data.
            textBox1->Text = String::Concat(S"The data type is ", 
                myDataObject->GetData(myType)->GetType()->Name, S".");
        } else
            MessageBox::Show(S"The specified data is not stored in the data object.");
    }

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

IDataObject インターフェイス | IDataObject メンバ | System.Windows.Forms 名前空間 | IDataObject.GetDataPresent オーバーロードの一覧 | IDataObject.SetData | IDataObject.GetData | DataObject.GetDataPresent