次の方法で共有


DataObject.GetFormats メソッド (Boolean)

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

Overloads Public Overridable Function GetFormats( _
   ByVal autoConvert As Boolean _) As String() Implements IDataObject.GetFormats
[C#]
public virtual string[] GetFormats(boolautoConvert);
[C++]
public: virtual String* GetFormats(boolautoConvert)  __gc[];
[JScript]
public function GetFormats(
   autoConvert : Boolean) : String[];

パラメータ

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

戻り値

String 型の配列。このオブジェクトに格納されているデータがサポートするすべての形式のリストが含まれます。

実装

IDataObject.GetFormats

解説

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

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

使用例

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

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

 
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++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

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

参照

DataObject クラス | DataObject メンバ | System.Windows.Forms 名前空間 | DataObject.GetFormats オーバーロードの一覧 | GetData | SetData | DataFormats | GetDataPresent