DataObject.GetFormats DataObject.GetFormats DataObject.GetFormats DataObject.GetFormats Method

定义

返回存储在此 DataObject 中的数据所关联的或可以转换为的所有格式的列表。Returns a list of all formats that data stored in this DataObject is associated with or can be converted to.

重载

GetFormats() GetFormats() GetFormats() GetFormats()

返回存储在此 DataObject 中的数据所关联的或可以转换为的所有格式的列表。Returns a list of all formats that data stored in this DataObject is associated with or can be converted to.

GetFormats(Boolean) GetFormats(Boolean) GetFormats(Boolean) GetFormats(Boolean)

返回存储在此 DataObject 中的数据所关联的或可以转换为的所有格式的列表,同时使用自动转换参数来确定是只检索本机数据格式,还是检索此数据可以转换为的所有格式。Returns a list of all formats that data stored in this DataObject is associated with or can be converted to, using an automatic conversion parameter to determine whether to retrieve only native data formats or all formats that the data can be converted to.

GetFormats() GetFormats() GetFormats() GetFormats()

返回存储在此 DataObject 中的数据所关联的或可以转换为的所有格式的列表。Returns a list of all formats that data stored in this DataObject is associated with or can be converted to.

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 的数组,它包含所有格式的列表,并且这些格式受存储在此对象中的数据支持。An array of type String, containing a list of all formats that are supported by the data stored in this object.

实现

示例

下面的代码示例将查询DataObject与数据关联的格式, 以及数据可以转换为的格式。The following code example queries a DataObject for the formats associated with its data, and the formats that the data can be converted to. 生成的列表显示在文本框中。The resulting list is displayed in a text box. 此代码需要已textBox1创建的。This code requires that textBox1 has been created.

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 'GetAllFormats 

注解

调用此方法可在调用GetData之前获取受支持的数据格式。Call this method to get the supported data formats before calling GetData. 有关DataFormats预定义格式, 请参阅。See DataFormats for the predefined formats.

备注

如果数据已存储, 则可以将其转换为另一种格式, 这种格式指定允许该转换, 并且请求的格式与存储格式兼容。Data can be converted to another format if it was stored specifying that conversion is allowed and if the requested format is compatible with the stored format. 例如, 以 Unicode 形式存储的数据可以转换为文本。For example, data stored as Unicode can be converted to text.

另请参阅

GetFormats(Boolean) GetFormats(Boolean) GetFormats(Boolean) GetFormats(Boolean)

返回存储在此 DataObject 中的数据所关联的或可以转换为的所有格式的列表,同时使用自动转换参数来确定是只检索本机数据格式,还是检索此数据可以转换为的所有格式。Returns a list of all formats that data stored in this DataObject is associated with or can be converted to, using an automatic conversion parameter to determine whether to retrieve only native data formats or all formats that the data can be converted to.

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 Boolean Boolean Boolean

值为 true 时,检索存储在此 DataObject 中的数据所关联的或可以转换成的所有格式;值为 false 时,仅检索本机数据格式。true to retrieve all formats that data stored in this DataObject is associated with, or can be converted to; false to retrieve only native data formats.

返回

String[]

一个类型为 String 的数组,它包含所有格式的列表,并且这些格式受存储在此对象中的数据支持。An array of type String, containing a list of all formats that are supported by the data stored in this object.

实现

示例

下面的代码示例将查询DataObject与数据关联的格式。The following code example queries a DataObject for the formats associated with its data. 第一个查询将autoConvert参数指定为false, 因此只返回数据的本机格式。The first query specifies the autoConvert parameter as false, so only the native format of the data is returned. 第二个查询将autoConvert参数指定true为, 因此格式列表包括数据可以转换为的格式。The second query specifies the autoConvert parameter as true, so the list of formats includes the formats that the data can be converted to.

此代码需要已textBox1创建的。This code requires that textBox1 has been created.

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 'GetAllFormats2 

注解

调用此方法可在调用GetData之前获取受支持的数据格式。Call this method to get the supported data formats before calling GetData. 有关DataFormats预定义格式, 请参阅。See DataFormats for the predefined formats.

备注

如果数据已存储, 则可以将其转换为另一种格式, 这种格式指定允许该转换, 并且请求的格式与存储格式兼容。Data can be converted to another format if it was stored specifying that conversion is allowed and if the requested format is compatible with the stored format. 例如, 以 Unicode 形式存储的数据可以转换为文本。For example, data stored as Unicode can be converted to text.

另请参阅

适用于