次の方法で共有


DataObject.GetDataPresent メソッド

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

オーバーロードの一覧

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

[Visual Basic] Overloads Public Overridable Function GetDataPresent(String) As Boolean Implements IDataObject.GetDataPresent

[C#] public virtual bool GetDataPresent(string);

[C++] public: virtual bool GetDataPresent(String*);

[JScript] public function GetDataPresent(String) : Boolean;

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

[Visual Basic] Overloads Public Overridable Function GetDataPresent(Type) As Boolean Implements IDataObject.GetDataPresent

[C#] public virtual bool GetDataPresent(Type);

[C++] public: virtual bool GetDataPresent(Type*);

[JScript] public function GetDataPresent(Type) : Boolean;

データを指定形式に変換するかどうかを判断するための自動変換パラメータを使用して、このインスタンスに格納されているデータが指定したデータ形式に関連付けられているかどうかを確認します。

[Visual Basic] Overloads Public Overridable Function GetDataPresent(String, Boolean) As Boolean Implements IDataObject.GetDataPresent

[C#] public virtual bool GetDataPresent(string, bool);

[C++] public: virtual bool GetDataPresent(String*, bool);

[JScript] public function GetDataPresent(String, Boolean) : Boolean;

使用例

[Visual Basic, C#, C++] 現在 DataObject に格納されているデータが、指定された形式に関連付けられているかどうかを確認する例を次に示します。まず、新しいインスタンスを文字列で初期化します。文字列の形式をテキストに指定します。

[Visual Basic, C#, C++] 次に、 autoConvert パラメータを false に指定して、テキスト形式に関連付けられているデータを DataObject に問い合わせます。このクエリの結果はテキスト ボックスに表示されます。

[Visual Basic, C#, C++] 次に、 autoConvert パラメータを true に指定して、文字列形式に関連付けられているデータを DataObject に問い合わせます。結果はテキスト ボックスに表示されます。このコードは、 textBox1 が作成されていることを前提にしています。

[Visual Basic, C#, C++] メモ   ここでは、GetDataPresent のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。

 
Private Sub GetIfPresent3()
    ' Creates a new data object using a string and the text format.
    Dim myDataObject As New DataObject(DataFormats.Text, "Another string")
    
    ' Prints the string in a text box with autoconvert = false.
    If myDataObject.GetDataPresent("System.String", False) Then
        ' Prints the string in a text box.
        textBox1.Text = myDataObject.GetData("System.String", False).ToString() & ControlChars.Cr
    Else
        textBox1.Text = "Could not convert data to specified format" & ControlChars.Cr
    End If 
    ' Prints the string in a text box with autoconvert = true.
    textBox1.Text &= "With autoconvert = true, you can convert text to string format. " & _
                    "String is: " & myDataObject.GetData("System.String", True).ToString()
End Sub 'GetIfPresent3

[C#] 
private void GetIfPresent3() {
    // Creates a new data object using a string and the text format.
    DataObject myDataObject = new DataObject(DataFormats.Text, "Another string");
 
    // Prints the string in a text box with autoconvert = false.
    if(myDataObject.GetDataPresent("System.String", false)) {
       // Prints the string in a text box.
       textBox1.Text = myDataObject.GetData("System.String", false).ToString() + '\n';
    } else
       textBox1.Text = "Could not convert data to specified format" + '\n';
 
    // Prints the string in a text box with autoconvert = true.
    textBox1.Text += "With autoconvert = true, you can convert text to string format. " +
       "String is: " + myDataObject.GetData("System.String", true).ToString();
 }
 

[C++] 
private:
void GetIfPresent3() {
    // Creates a new data object using a string and the text format.
    DataObject* myDataObject = new DataObject(DataFormats::Text, S"Another string");
 
    // Prints the string in a text box with autoconvert = false.
    if(myDataObject->GetDataPresent(S"System.String", false)) {
       // Prints the string in a text box.
       textBox1->Text = String::Concat( myDataObject->GetData(S"System.String",false), S"\n");
    } else
       textBox1->Text = S"Could not convert data to specified format\n";
 
    // Prints the string in a text box with autoconvert = true.
    textBox1->Text = String::Format( S"{0}With autoconvert = true, you can convert text to string format. String is: {1}",
       textBox1->Text, myDataObject->GetData(S"System.String",true) );
 }
 

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

参照

DataObject クラス | DataObject メンバ | System.Windows.Forms 名前空間