IDataObject.GetFormats Metoda

Definicja

Zwraca listę wszystkich formatów, z którymi są skojarzone dane przechowywane w tym wystąpieniu lub do których można je przekonwertować.

Przeciążenia

GetFormats()

Zwraca listę wszystkich formatów, z którymi są skojarzone dane przechowywane w tym wystąpieniu lub do których można je przekonwertować.

GetFormats(Boolean)

Pobiera listę wszystkich formatów, z którymi dane przechowywane w tym wystąpieniu są skojarzone lub można je przekonwertować przy użyciu wartości logicznej w celu określenia, czy pobrać wszystkie formaty, które można przekonwertować na lub tylko natywne formaty danych.

GetFormats()

Zwraca listę wszystkich formatów, z którymi są skojarzone dane przechowywane w tym wystąpieniu lub do których można je przekonwertować.

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

Zwraca

String[]

Tablica nazw, która reprezentuje listę wszystkich formatów obsługiwanych przez dane przechowywane w tym obiekcie.

Przykłady

W tym przykładzie użyto DataObject klasy , która implementuje IDataObjectmetodę GetFormats , aby zademonstrować użycie metody . Najpierw tworzy obiekt danych (myDataObject) przy użyciu ciągu i Text formatu. Następnie pobiera wszystkie formaty danych i formaty konwersji danych w obiekcie danych i wyświetla listę wynikową w oknie komunikatu. W tym przykładzie przyjęto założenie, że utworzono Form nazwę 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

Uwagi

Wywołaj tę metodę, aby uzyskać obsługiwane formaty danych przed wywołaniem GetData metody . Zobacz klasę DataFormats dla wstępnie zdefiniowanych formatów.

Uwaga

Dane można przekonwertować na inny format, jeśli zostały zapisane, określając, że konwersja jest dozwolona, a żądany format jest zgodny z zapisanym formatem. Na przykład dane przechowywane jako Unicode można przekonwertować na tekst.

Aby zapoznać się z implementacją tej metody, zobacz DataObject.GetFormats.

Zobacz też

Dotyczy

GetFormats(Boolean)

Pobiera listę wszystkich formatów, z którymi dane przechowywane w tym wystąpieniu są skojarzone lub można je przekonwertować przy użyciu wartości logicznej w celu określenia, czy pobrać wszystkie formaty, które można przekonwertować na lub tylko natywne formaty danych.

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

Parametry

autoConvert
Boolean

true aby pobrać wszystkie formaty, z którymi są skojarzone dane przechowywane w tym wystąpieniu, lub można je przekonwertować na; false aby pobrać tylko natywne formaty danych.

Zwraca

String[]

Tablica nazw, która reprezentuje listę wszystkich formatów obsługiwanych przez dane przechowywane w tym obiekcie.

Przykłady

W tym przykładzie użyto DataObject klasy , która implementuje IDataObjectmetodę GetFormats , aby zademonstrować użycie metody . Najpierw tworzy obiekt danych (myDataObject) przy użyciu ciągu i UnicodeText formatu. Następnie tworzy dwa zapytania w celu pobrania formatów skojarzonych z danymi. W pierwszym zapytaniu ustawia autoConvert parametr na false wartość : w tym przypadku zwracany jest tylko natywny format danych. W drugim zapytaniu ustawia autoConvert parametr na true, aby pobierał listę formatów, w tym formaty, na które można przekonwertować dane. W każdym przypadku wynikowa lista jest wyświetlana w oknie komunikatu. W tym przykładzie przyjęto założenie, że utworzono Form nazwę 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

Uwagi

Wywołaj tę metodę, aby uzyskać obsługiwane formaty danych przed wywołaniem GetData metody . Zobacz klasę DataFormats dla wstępnie zdefiniowanych formatów.

Uwaga

Dane można przekonwertować na inny format, jeśli zostały zapisane, określając, że konwersja jest dozwolona, a żądany format jest zgodny z zapisanym formatem. Na przykład dane przechowywane jako Unicode można przekonwertować na tekst.

Aby zapoznać się z implementacją tej metody, zobacz DataObject.GetFormats.

Zobacz też

Dotyczy