IDataObject.GetDataPresent メソッド
インスタンスに格納されているデータが、指定した形式に関連付けられているかどうかを確認します。
オーバーロードの一覧
インスタンスに格納されているデータが、指定した形式と関連付けられているかどうかや、その形式に変換できるかどうかを確認します。
[Visual Basic] Overloads Function GetDataPresent(String) As Boolean
インスタンスに格納されているデータが、指定した形式と関連付けられているかどうかや、その形式に変換できるかどうかを確認します。
[Visual Basic] Overloads Function GetDataPresent(Type) As Boolean
[JScript] function GetDataPresent(Type) : Boolean;
インスタンスに格納されているデータが、指定した形式に関連付けられているかどうかを確認します。データを指定形式に変換できるかどうかを確認するためにブール値を使用します。
[Visual Basic] Overloads Function GetDataPresent(String, Boolean) As Boolean
[JScript] function GetDataPresent(String, Boolean) : Boolean;
使用例
[Visual Basic, C#, C++] この例では、 IDataObject を実装する DataObject クラスを使用して GetDataPresent メソッドの使用法を示します。最初に、文字列および Text 形式を使用してデータ オブジェクト (myDataObject
) を作成します。次に、 autoConvert パラメータを false に設定して、 Text 形式に関連付けられているデータをオブジェクトに問い合わせます。これは失敗し、その結果が "Message #1" というラベルの付いたメッセージ ボックスに表示されます。2 回目には、 autoConvert パラメータを true に設定します。これは成功し、その結果が "Message #2" というラベルの付いたメッセージ ボックスに表示されます。この例は、 Form1
という名前の Form を作成済みであることを前提にしています。
[Visual Basic, C#, C++] メモ ここでは、GetDataPresent のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。
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 'GetDataPresent3
[C#]
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");
}
[C++]
private:
void GetDataPresent3() {
// Creates a new data object using a string and the Text format.
DataObject* myDataObject = new DataObject(DataFormats::Text, S"My String");
// Checks whether the string can be displayed with autoConvert equal to false.
if (myDataObject->GetDataPresent(S"System::String", false))
MessageBox::Show(
myDataObject->GetData(S"System::String", false)->ToString(),
S"Message #1");
else
MessageBox::Show(
S"Cannot convert data to the specified format with autoConvert set to false.",
S"Message #1");
// Displays the string with autoConvert equal to true.
MessageBox::Show(String::Concat(S"Now that autoConvert is true, you can convert ",
myDataObject->GetData(S"System::String", true),
S" to string format."), S"Message #2");
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
参照
IDataObject インターフェイス | IDataObject メンバ | System.Windows.Forms 名前空間