IDataObject.GetFormats IDataObject.GetFormats IDataObject.GetFormats IDataObject.GetFormats Method

定义

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

重载

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

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

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

获取该实例中存储的数据所关联或可转换到的所有格式的列表,同时使用一个布尔值确定是检索数据可转换到的所有格式,还是只检索本机数据格式。Gets a list of all formats that data stored in this instance is associated with or can be converted to, using a Boolean value to determine whether to retrieve all formats that the data can be converted to or only native data formats.

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

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

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

返回

String[]

一组名称,表示此对象中存储的数据所支持的所有格式列表。An array of the names that represents a list of all formats that are supported by the data stored in this object.

示例

此示例使用DataObject实现IDataObject的类来GetFormats演示方法的用法。This example uses the DataObject class, which implements IDataObject, to demonstrate the use of the GetFormats method. 首先, 它使用字符串myDataObject Text和格式创建数据对象 ()。First, it creates a data object (myDataObject) using a string and the Text format. 然后, 它检索数据对象中的所有数据格式和数据转换格式, 并在消息框中显示结果列表。Then it retrieves all the data formats and data conversion formats in the data object, and displays the resulting list in a message box. 此示例假设您已创建了一个FormForm1为的。This example assumes that you have created a Form named 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方法之前调用此方法以获取支持的数据格式。Call this method to get the supported data formats before calling the GetData method. 有关预定义格式, 请参阅类。DataFormatsSee the DataFormats class 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.

有关此方法的实现, 请参见DataObject.GetFormatsFor an implementation of this method, see DataObject.GetFormats.

另请参阅

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

获取该实例中存储的数据所关联或可转换到的所有格式的列表,同时使用一个布尔值确定是检索数据可转换到的所有格式,还是只检索本机数据格式。Gets a list of all formats that data stored in this instance is associated with or can be converted to, using a Boolean value to determine whether to retrieve all formats that the data can be converted to or only native data formats.

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

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

返回

String[]

一组名称,表示此对象中存储的数据所支持的所有格式列表。An array of the names that represents a list of all formats that are supported by the data stored in this object.

示例

此示例使用DataObject实现IDataObject的类来GetFormats演示方法的用法。This example uses the DataObject class, which implements IDataObject, to demonstrate the use of the GetFormats method. 首先, 它使用字符串myDataObject UnicodeText和格式创建数据对象 ()。First, it creates a data object (myDataObject) using a string and the UnicodeText format. 然后, 它将执行两个查询以获取与数据关联的格式。Then it makes two queries to get the formats associated with the data. 在第一个查询中, 它将autoConvert参数设置false为: 在这种情况下, 只返回数据的本机格式。In the first query, it sets the autoConvert parameter to false : in this case, only the native format of the data is returned. 在第二个查询中, 它autoConvert将参数true设置为, 以便它获取格式列表, 其中包括数据可以转换为的格式。In the second query, it sets the autoConvert parameter to true, so that it gets the list of formats, including the formats that the data can be converted to. 在每种情况下, 生成的列表显示在一个消息框中。In each case, the resulting list is displayed in a message box. 此示例假设您已创建了一个FormForm1为的。This example assumes that you have created a Form named 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方法之前调用此方法以获取支持的数据格式。Call this method to get the supported data formats before calling the GetData method. 有关预定义格式, 请参阅类。DataFormatsSee the DataFormats class 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.

有关此方法的实现, 请参见DataObject.GetFormatsFor an implementation of this method, see DataObject.GetFormats.

另请参阅

适用于