IDataObject.GetFormats メソッド (Boolean)

インスタンスに格納されているデータが関連付けられている形式、またはそのデータを変換できる形式のリストを取得します。データを変換できる形式をすべて取得するのか、ネイティブ データ形式だけを取得するのかを確認するためにブール値を使用します。

Function GetFormats( _
   ByVal autoConvert As Boolean _) As String()
[C#]
string[] GetFormats(
   boolautoConvert);
[C++]
String* GetFormats(
   boolautoConvert)  __gc[];
[JScript]
function GetFormats(
   autoConvert : Boolean) : String[];

パラメータ

  • autoConvert
    インスタンスに格納されたデータが関連付けられている形式、またはそのデータを変換できる形式をすべて取得する場合は true 。ネイティブ データ形式だけを取得する場合は false

戻り値

オブジェクトに格納されているデータがサポートする形式すべてのリストを表す名前の配列。

解説

サポートされているデータ形式を取得するには、 GetData を呼び出す前に、このメソッドを呼び出します。定義済みの形式については、 DataFormats クラスのトピックを参照してください。

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

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

使用例

[Visual Basic, C#, C++] この例では、 IDataObject を実装する DataObject クラスを使用して、 GetFormats メソッドの使用法を示します。最初に、文字列および UnicodeText 形式を使用してデータ オブジェクト (myDataObject) を作成します。次に、データに関連付けられている形式を取得するために、クエリを 2 回作成します。最初のクエリでは、 autoConvert パラメータを false に指定します。この場合、データのネイティブ形式だけが返されます。2 回目のクエリでは、 autoConvert パラメータを true に設定します。この場合は、データの変換対象となりうる形式を含んでいる形式の一覧を取得します。いずれの場合も、結果の一覧がメッセージ ボックスに表示されます。この例は、 Form1 という名前の Form を作成済みであることを前提にしています。

 
Private Sub GetFormats2()
   ' Creates a new data object using a string and the UnicodeText format.
   Dim myDataObject As New DataObject(DataFormats.UnicodeText, "My text string")
   
   ' Gets the original data formats in the data object by setting the automatic
   ' conversion parameter to false.
   Dim myFormatsArray As [String]() = myDataObject.GetFormats(False)
   
   ' Stores the results in a string.
   Dim theResult As String = "The original format associated with the data is:" & vbCr
   Dim i As Integer
   For i = 0 To myFormatsArray.Length - 1
      theResult += myFormatsArray(i) + vbCr
   Next i 
   ' Gets all data formats and data conversion formats for the data object.
   myFormatsArray = myDataObject.GetFormats(True)
   
   ' Stores the results in the string.
   theResult += vbCr + "The data format(s) and conversion format(s) associated with " & _
     "the data are:" & vbCr
   For i = 0 To myFormatsArray.Length - 1
      theResult += myFormatsArray(i) + vbCr
   Next i
   ' Displays the results.
   MessageBox.Show(theResult)
End Sub 'GetFormats2

[C#] 
private void GetFormats2() 
{
    // Creates a new data object using a string and the UnicodeText format.
    DataObject myDataObject = new DataObject(DataFormats.UnicodeText, "My text string");

    // Gets the original data formats in the data object by setting the automatic
    // conversion parameter to false.
    String[] myFormatsArray = myDataObject.GetFormats(false);

    // Stores the results in a string.
    string theResult = "The original format associated with the data is:\n";
    for(int i = 0; i < myFormatsArray.Length; i++)
        theResult += myFormatsArray[i] + '\n';

    // Gets all data formats and data conversion formats for the data object.
    myFormatsArray = myDataObject.GetFormats(true);
 
    // Stores the results in the string.
    theResult += "\nThe data format(s) and conversion format(s) associated with " +
        "the data are:\n";
    for(int i = 0; i < myFormatsArray.Length; i++)
        theResult += myFormatsArray[i] + '\n';

    // Displays the results.
    MessageBox.Show(theResult);
}

[C++] 
private:
    void GetFormats2() {
        // Creates a new data object using a string and the UnicodeText format.
        DataObject* myDataObject = new DataObject(DataFormats::UnicodeText, S"My text string");

        // Gets the original data formats in the data object by setting the automatic
        // conversion parameter to false.
        String*  myFormatsArray[] = myDataObject->GetFormats(false);

        // Stores the results in a string.
        String* theResult = S"The original format associated with the data is:\n";
        for (int i = 0; i < myFormatsArray->Length; i++)
            theResult = String::Concat(theResult, myFormatsArray->Item[i], S"\n");

        // Gets all data formats and data conversion formats for the data object.
        myFormatsArray = myDataObject->GetFormats(true);

        // Stores the results in the string.
        theResult = String::Concat(theResult,
            S"\nThe data format(s) and conversion format(s) associated with the data are:\n");
        for (int i = 0; i < myFormatsArray->Length; i++)
            theResult = String::Concat(theResult, myFormatsArray->Item[i], S"\n");

        // Displays the results.
        MessageBox::Show(theResult);
    }

[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.GetFormats オーバーロードの一覧 | DataObject.GetFormats | DataObject.GetData