編輯

共用方式為


IDataObject.GetFormats Method

Definition

Returns a list of all formats that data stored in this instance is associated with or can be converted to.

Overloads

GetFormats()

Returns a list of all formats that data stored in this instance is associated with or can be converted to.

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()

Source:
IDataObject.cs
Source:
IDataObject.cs
Source:
IDataObject.cs

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()

Returns

String[]

An array of the names that represents a list of all formats that are supported by the data stored in this object.

Examples

This example uses the DataObject class, which implements IDataObject, to demonstrate the use of the GetFormats method. 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. 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

Remarks

Call this method to get the supported data formats before calling the GetData method. See the DataFormats class for the predefined formats.

Note

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. For example, data stored as Unicode can be converted to text.

For an implementation of this method, see DataObject.GetFormats.

See also

Applies to

GetFormats(Boolean)

Source:
IDataObject.cs
Source:
IDataObject.cs
Source:
IDataObject.cs

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()

Parameters

autoConvert
Boolean

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.

Returns

String[]

An array of the names that represents a list of all formats that are supported by the data stored in this object.

Examples

This example uses the DataObject class, which implements IDataObject, to demonstrate the use of the GetFormats method. 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. In the first query, it sets the autoConvert parameter to false : in this case, only the native format of the data is returned. 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. 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

Remarks

Call this method to get the supported data formats before calling the GetData method. See the DataFormats class for the predefined formats.

Note

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. For example, data stored as Unicode can be converted to text.

For an implementation of this method, see DataObject.GetFormats.

See also

Applies to