DataObject.GetFormats Metoda

Definicja

Zwraca listę wszystkich formatów, z którymi są skojarzone dane przechowywane w tym DataObject obiekcie 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 DataObject obiekcie lub do których można je przekonwertować.

GetFormats(Boolean)

Zwraca listę wszystkich formatów, z którymi są skojarzone dane przechowywane w tym DataObject obiekcie lub można je przekonwertować przy użyciu parametru konwersji automatycznej w celu określenia, czy pobrać tylko natywne formaty danych, czy wszystkie formaty, na które można przekonwertować dane.

GetFormats()

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

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

Zwraca

String[]

Tablica typu String, zawierająca listę wszystkich formatów obsługiwanych przez dane przechowywane w tym obiekcie.

Implementuje

Przykłady

Poniższy przykład kodu wysyła zapytanie DataObject dotyczące formatów skojarzonych z danymi oraz formatów, na które można przekonwertować dane. Wynikowa lista jest wyświetlana w polu tekstowym. Ten kod wymaga textBox1 utworzenia.

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

Uwagi

Wywołaj tę metodę, aby uzyskać obsługiwane formaty danych przed wywołaniem metody GetData. Zobacz, aby zapoznać się DataFormats ze wstępnie zdefiniowanymi formatami.

Uwaga

Dane można przekonwertować na inny format, jeśli były przechowywane, 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.

Zobacz też

Dotyczy

GetFormats(Boolean)

Zwraca listę wszystkich formatów, z którymi są skojarzone dane przechowywane w tym DataObject obiekcie lub można je przekonwertować przy użyciu parametru konwersji automatycznej w celu określenia, czy pobrać tylko natywne formaty danych, czy wszystkie formaty, na które można przekonwertować dane.

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

Parametry

autoConvert
Boolean

true aby pobrać wszystkie formaty, z którymi są przechowywane dane, DataObject są skojarzone lub można je przekonwertować na; false w celu pobrania tylko natywnych formatów danych.

Zwraca

String[]

Tablica typu String, zawierająca listę wszystkich formatów obsługiwanych przez dane przechowywane w tym obiekcie.

Implementuje

Przykłady

Poniższy przykład kodu wysyła zapytanie DataObject dotyczące formatów skojarzonych z danymi. Pierwsze zapytanie określa autoConvert parametr jako false, więc zwracany jest tylko natywny format danych. Drugie zapytanie określa autoConvert parametr jako true, więc lista formatów zawiera formaty, na które można przekonwertować dane.

Ten kod wymaga textBox1 utworzenia.

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

Uwagi

Wywołaj tę metodę, aby uzyskać obsługiwane formaty danych przed wywołaniem metody GetData. Zobacz, aby zapoznać się DataFormats ze wstępnie zdefiniowanymi formatami.

Uwaga

Dane można przekonwertować na inny format, jeśli były przechowywane, 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.

Zobacz też

Dotyczy