DataObject.GetFormats 方法

定義

傳回所有格式的清單,儲存於這個 DataObject 中的資料與這些格式建立關聯,或是該資料可以轉換成這些格式。

多載

GetFormats()

傳回所有格式的清單,儲存於這個 DataObject 中的資料與這些格式建立關聯,或是該資料可以轉換成這些格式。

GetFormats(Boolean)

使用自動轉換參數判斷是否只擷取原生資料格式,或擷取所有可以轉換的格式,傳回與儲存於這個 DataObject 中之資料建立關聯或者所有可以轉換之格式的清單。

GetFormats()

傳回所有格式的清單,儲存於這個 DataObject 中的資料與這些格式建立關聯,或是該資料可以轉換成這些格式。

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

傳回

String[]

String 類型的陣列,包含儲存於這個物件的資料其所支援格式清單。

實作

範例

下列程式碼範例會查詢 DataObject 與其資料相關聯的格式,以及資料可轉換成的格式。 產生的清單會顯示在文字方塊中。 此程式碼需要 textBox1 已建立。

private:
   void GetAllFormats()
   {
      // Creates a new data object using a string and the text format.
      DataObject^ myDataObject = gcnew DataObject( DataFormats::Text,"Another string" );
      
      // Gets all the data formats and data conversion formats in the DataObject.
      array<String^>^ arrayOfFormats = myDataObject->GetFormats();
      
      // Prints the results.
      textBox1->Text = "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 ], "\n" );
      }
   }
private void GetAllFormats() {
    // Creates a new data object using a string and the text format.
    DataObject myDataObject = new DataObject(DataFormats.Text, "Another string");
 
    // Gets all the data formats and data conversion formats in the DataObject.
    String[] arrayOfFormats = myDataObject.GetFormats();
 
    // 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';
 }
Private Sub GetAllFormats()
    ' Creates a new data object using a string and the text format.
    Dim myDataObject As New DataObject(DataFormats.Text, "Another string")
    
    ' Gets all the data formats and data conversion formats in the DataObject.
    Dim arrayOfFormats As String() = myDataObject.GetFormats()
    
    ' 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
End Sub

備註

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

注意

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

另請參閱

適用於

GetFormats(Boolean)

使用自動轉換參數判斷是否只擷取原生資料格式,或擷取所有可以轉換的格式,傳回與儲存於這個 DataObject 中之資料建立關聯或者所有可以轉換之格式的清單。

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

參數

autoConvert
Boolean

若要擷取與儲存於這個 DataObject 中的資料建立關聯或可以轉換的所有格式,則為 true;若只要擷取原生資料格式,則為 false

傳回

String[]

String 類型的陣列,包含儲存於這個物件的資料其所支援格式清單。

實作

範例

下列程式碼範例會查詢 DataObject ,以取得與其資料相關聯的格式。 第一個查詢會將 autoConvert 參數指定為 false ,因此只會傳回資料的原生格式。 第二個查詢會將 autoConvert 參數指定為 true ,因此格式清單會包含可轉換資料的格式。

此程式碼需要 textBox1 已建立。

private:
   void GetAllFormats2()
   {
      // Creates a new data object using a string and the text format.
      DataObject^ myDataObject = gcnew DataObject( DataFormats::Text,"Another string" );
      
      // Gets the original data formats in the DataObject.
      array<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 = String::Concat( 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 = String::Concat( 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 = String::Concat( textBox1->Text, arrayOfFormats[ i ], "\n" );
      }
   }
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';
 }
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

備註

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

注意

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

另請參閱

適用於