IDataObject.GetFormats 方法

定義

傳回與儲存於這個執行個體中的資料相關的,或者可以轉換的所有格式的清單。

多載

GetFormats()

傳回與儲存於這個執行個體中的資料相關的,或者可以轉換的所有格式的清單。

GetFormats(Boolean)

取得與儲存於這個執行個體中的資料相關的,或者可以轉換的所有格式清單,使用布林值來決定要擷取資料可以轉換的所有格式,還是只要擷取原生的資料格式。

GetFormats()

傳回與儲存於這個執行個體中的資料相關的,或者可以轉換的所有格式的清單。

public:
 cli::array <System::String ^> ^ GetFormats();
public string[] GetFormats ();
abstract member GetFormats : unit -> string[]
Public Function GetFormats () As String()

傳回

String[]

名稱陣列,表示這個物件中儲存的資料所支援的所有格式的清單。

範例

這個範例會使用 DataObject 實作 IDataObject 的 類別來示範 方法的使用 GetFormats 方式。 首先,它會使用字串和 Text 格式建立資料物件 (myDataObject) 。 然後它會擷取資料物件中的所有資料格式和資料轉換格式,並在訊息方塊中顯示產生的清單。 此範例假設您已建立 Form 名為 的 Form1

private:
   void GetFormats1()
   {
      // Creates a data object using a string and the Text format.
      DataObject^ myDataObject = gcnew DataObject( DataFormats::Text,"My text string" );
      
      // Gets all the data formats and data conversion formats in the data object.
      array<String^>^allFormats = myDataObject->GetFormats();
      
      // Creates the string that contains the formats.
      String^ theResult = "The format(s) associated with the data are: \n";
      for ( int i = 0; i < allFormats->Length; i++ )
         theResult = theResult + allFormats[ i ] + "\n";
      
      // Displays the result in a message box.
      MessageBox::Show( theResult );
   }
private void GetFormats1() 
{
    // Creates a data object using a string and the Text format.
    DataObject myDataObject = new DataObject(DataFormats.Text, "My text string");
 
    // Gets all the data formats and data conversion formats in the data object.
    String[] allFormats = myDataObject.GetFormats();

    // Creates the string that contains the formats.
    string theResult = "The format(s) associated with the data are: " + '\n';
    for(int i = 0; i < allFormats.Length; i++)
        theResult += allFormats[i] + '\n';
    // Displays the result in a message box.
    MessageBox.Show(theResult);
}
Private Sub GetFormats1()
   ' Creates a data object using a string and the Text format.
   Dim myDataObject As New DataObject(DataFormats.Text, "My text string")
   
   ' Gets all the data formats and data conversion formats in the data object.
   Dim allFormats As [String]() = myDataObject.GetFormats()
   
   ' Creates the string that contains the formats.
   Dim theResult As String = "The format(s) associated with the data are: " & _
                vbCr
   Dim i As Integer
   For i = 0 To allFormats.Length - 1
      theResult += allFormats(i) + vbCr
   Next i 
   ' Displays the result in a message box.
   MessageBox.Show(theResult)
End Sub

備註

呼叫此方法以取得支援的資料格式,然後再呼叫 GetData 方法。 DataFormats如需預先定義的格式,請參閱 類別。

注意

如果資料儲存指定允許轉換,而且要求的格式與預存格式相容,則可以將資料轉換成另一種格式。 例如,儲存為 Unicode 的資料可以轉換成文字。

如需此方法的實作,請參閱 DataObject.GetFormats

另請參閱

適用於

GetFormats(Boolean)

取得與儲存於這個執行個體中的資料相關的,或者可以轉換的所有格式清單,使用布林值來決定要擷取資料可以轉換的所有格式,還是只要擷取原生的資料格式。

public:
 cli::array <System::String ^> ^ GetFormats(bool autoConvert);
public string[] GetFormats (bool autoConvert);
abstract member GetFormats : bool -> string[]
Public Function GetFormats (autoConvert As Boolean) As String()

參數

autoConvert
Boolean

若要擷取與儲存於這個執行個體中的資料相關的、或是可以轉換的所有格式則為 true;若只要擷取原生的資料格式則為 false

傳回

String[]

名稱陣列,表示這個物件中儲存的資料所支援的所有格式的清單。

範例

這個範例會使用 DataObject 實作 IDataObject 的 類別來示範 方法的使用 GetFormats 方式。 首先,它會使用字串和 UnicodeText 格式建立資料物件 (myDataObject) 。 然後,它會進行兩個查詢,以取得與資料相關聯的格式。 在第一個查詢中,它會將 autoConvert 參數設定為 false :在此情況下,只會傳回資料的原生格式。 在第二個查詢中,它會將 autoConvert 參數設定為 true ,以便取得格式清單,包括資料可轉換成的格式。 在每個案例中,產生的清單會顯示在訊息方塊中。 此範例假設您已建立 Form 名為 的 Form1

private:
   void GetFormats2()
   {
      // Creates a new data object using a string and the UnicodeText format.
      DataObject^ myDataObject = gcnew DataObject( DataFormats::UnicodeText,"My text string" );
      
      // Gets the original data formats in the data object by setting the automatic
      // conversion parameter to false.
      array<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 = 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 = theResult + "\nThe data format(s) and conversion format(s) associated with the data are:\n";
      for ( int i = 0; i < myFormatsArray->Length; i++ )
         theResult = theResult + myFormatsArray[ i ] + "\n";
      
      // Displays the results.
      MessageBox::Show( theResult );
   }
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);
}
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

備註

呼叫此方法以取得支援的資料格式,然後再呼叫 GetData 方法。 DataFormats如需預先定義的格式,請參閱 類別。

注意

如果資料儲存指定允許轉換,而且要求的格式與預存格式相容,則可以將資料轉換成另一種格式。 例如,儲存為 Unicode 的資料可以轉換成文字。

如需此方法的實作,請參閱 DataObject.GetFormats

另請參閱

適用於