次の方法で共有


DataObject.GetFormats メソッド

このインスタンスに格納されたデータに関連付けられているすべての形式、または変換できるすべての形式のリストを返します。

オーバーロードの一覧

このインスタンスに格納されたデータに関連付けられているすべての形式、または変換できるすべての形式のリストを返します。

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

[C#] public virtual string[] GetFormats();

[C++] public: virtual String* GetFormats() __gc[];

[JScript] public function GetFormats() : String[];

自動変換パラメータを使用して、ネイティブのデータ形式だけを取得するのか、またはデータを変換することができるすべての形式を取得するのかを決定し、このインスタンスに格納されているデータに関連付けられている形式、あるいは変換できるすべての形式のリストを返します。

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

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

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

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

使用例

[Visual Basic, C#, C++] データに関連付けられている形式を DataObject に問い合わせる例を次に示します。最初のクエリは autoConvert パラメータを false に指定します。したがって、データのネイティブ形式だけが返されます。2 番目のクエリは autoConvert パラメータを true に指定します。したがって、形式のリストには、データを変換することができる形式が含まれます。

[Visual Basic, C#, C++] このコードは、 textBox1 が作成されていることを前提にしています。

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

 
Private Sub GetAllFormats2()
    ' Creates a new data object using a string and the text format.
    Dim myDataObject As New DataObject(DataFormats.Text, "Another string")
    
    ' Gets the original data formats in the DataObject.
    Dim arrayOfFormats As String() = myDataObject.GetFormats(False)
    
    ' Prints the results.
    textBox1.Text = "The format(s) associated with the data are: " & ControlChars.Cr
    Dim i As Integer
    For i = 0 To arrayOfFormats.Length - 1
        textBox1.Text += arrayOfFormats(i) + ControlChars.Cr
    Next i 
    ' Gets the all data formats and data conversion formats for the DataObject.
    arrayOfFormats = myDataObject.GetFormats(True)
    
    ' Prints the results.
    textBox1.Text += "The data formats and conversion format(s) associated with " & _
        "the data are: " & ControlChars.Cr
        
    For i = 0 To arrayOfFormats.Length - 1
        textBox1.Text += arrayOfFormats(i) + ControlChars.Cr
    Next i
End Sub 'GetAllFormats2 

[C#] 
private void GetAllFormats2() {
    // Creates a new data object using a string and the text format.
    DataObject myDataObject = new DataObject(DataFormats.Text, "Another string");
 
    // Gets the original data formats in the DataObject.
    String[] arrayOfFormats = myDataObject.GetFormats(false);
 
    // Prints the results.
    textBox1.Text = "The format(s) associated with the data are: " + '\n';
    for(int i=0; i<arrayOfFormats.Length; i++)
       textBox1.Text += arrayOfFormats[i] + '\n';
 
    // Gets the all data formats and data conversion formats for the DataObject.
    arrayOfFormats = myDataObject.GetFormats(true);
 
    // Prints the results.
    textBox1.Text += "The data formats and conversion format(s) associated with " +
       "the data are: " + '\n';
    for(int i=0; i<arrayOfFormats.Length; i++)
       textBox1.Text += arrayOfFormats[i] + '\n';
 }
 

[C++] 
private:
void GetAllFormats2() {
    // Creates a new data object using a string and the text format.
    DataObject* myDataObject = new DataObject(DataFormats::Text, S"Another string");
 
    // Gets the original data formats in the DataObject.
    String* arrayOfFormats[] = myDataObject->GetFormats(false);
 
    // Prints the results.
    textBox1->Text = S"The format(s) associated with the data are: \n";
    for(int i=0; i<arrayOfFormats->Length; i++)
       textBox1->Text = String::Concat( textBox1->Text, arrayOfFormats[i], S"\n" );
 
    // Gets the all data formats and data conversion formats for the DataObject.
    arrayOfFormats = myDataObject->GetFormats(true);
 
    // Prints the results.
    textBox1->Text = String::Format( S"{0}The data formats and conversion format(s) associated with the data are: \n", textBox1->Text );
    for(int i=0; i<arrayOfFormats->Length; i++)
       textBox1->Text = String::Concat( textBox1->Text, arrayOfFormats[i], S"\n" );
 }
 

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

参照

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