Per Mausklick bewerten und Feedback geben
MSDN
MSDN Library
.NET Entwicklung
System.Windows.Forms
DataObject-Klasse
DataObject-Methoden
GetFormats-Methode
 GetFormats-Methode (Boolean)
Diese Seite ist spezifisch für
Microsoft Visual Studio 2005/.NET Framework 2.0

Andere Versionen stehen ebenfalls zur Verfügung für:
.NET Framework-Klassenbibliothek
DataObject.GetFormats-Methode (Boolean)

Gibt eine Liste aller Formate zurück, denen in diesem DataObject gespeicherte Daten zugeordnet sind oder in die diese konvertiert werden können. Dabei wird mithilfe eines Parameters für die automatische Konvertierung bestimmt, ob nur systemeigene Datenformate abgerufen werden sollen oder sämtliche Formate, in die die Daten konvertiert werden können.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Visual Basic (Deklaration)
Public Overridable Function GetFormats ( _
    autoConvert As Boolean _
) As String()
Visual Basic (Verwendung)
Dim instance As DataObject
Dim autoConvert As Boolean
Dim returnValue As String()

returnValue = instance.GetFormats(autoConvert)
C#
public virtual string[] GetFormats (
    bool autoConvert
)
C++
public:
virtual array<String^>^ GetFormats (
    bool autoConvert
)
J#
public String[] GetFormats (
    boolean autoConvert
)
JScript
public function GetFormats (
    autoConvert : boolean
) : String[]

Parameter

autoConvert

true, wenn alle Formate, denen in diesem DataObject gespeicherte Daten zugeordnet sind, abgerufen werden sollen, oder wenn die Daten in diese Formate konvertiert werden können. false, wenn nur systemeigene Datenformate abgerufen werden sollen.

Rückgabewert

Ein Array vom Typ String mit einer Liste aller Formate, die von den in diesem Objekt gespeicherten Daten unterstützt werden.

Rufen Sie diese Methode vor einem Aufruf von GetData auf, um die unterstützten Datenformate abzurufen. Die vordefinierten Formate finden Sie unter DataFormats.

HinweisHinweis

Daten können in ein anderes Format konvertiert werden, wenn beim Speichern eine Konvertierung zugelassen wurde und das angeforderte Format mit dem gespeicherten Format kompatibel ist. Als Unicode gespeicherte Daten können beispielsweise in Text konvertiert werden.

Im folgenden Codebeispiel wird in einem DataObject eine Abfrage nach den Formaten durchgeführt, die den Daten zugeordnet sind. In der ersten Abfrage wird der autoConvert-Parameter mit false angegeben, sodass nur das systemeigene Format der Daten zurückgegeben wird. In der zweiten Abfrage wird der autoConvert-Parameter mit true angegeben, sodass die Liste der Formate auch die Formate enthält, in die die Daten konvertiert werden können.

Für diesen Code muss textBox1 erstellt worden sein.

Visual Basic
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 
C#
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';
 }
 
C++
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" );
      }
   }
J#
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.set_Text("The format(s) associated with the data are: " + '\n');
    for (int i = 0; i < arrayOfFormats.get_Length(); i++) {
        textBox1.set_Text(textBox1.get_Text() 
            + arrayOfFormats.get_Item(i) + '\n');
    }

    // Gets the all data formats and data conversion formats for 
    // the DataObject.
    arrayOfFormats = myDataObject.GetFormats(true);

    // Prints the results.
    textBox1.set_Text(textBox1.get_Text() 
        + "The data formats and conversion format(s) "  
        + "associated with the data are: " + '\n');
    for (int i = 0; i < arrayOfFormats.get_Length(); i++) {
        textBox1.set_Text(textBox1.get_Text() 
            + arrayOfFormats.get_Item(i) + '\n');
    }
} //GetAllFormats2 

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0
© 2009 Microsoft Corporation. Alle Rechte vorbehalten. Nutzungsbedingungen  |  Markenzeichen  |  Informationen zur Datensicherheit
Page view tracker