DataFormats Klasse

Definition

Stellt staticvordefinierte Clipboard Formatnamen bereit. Verwenden Sie diese, um das Format der Daten zu identifizieren, die Sie in einem IDataObject.

public ref class DataFormats
public class DataFormats
type DataFormats = class
Public Class DataFormats
Vererbung
DataFormats

Beispiele

Im folgenden Codebeispiel wird ein neues Datenformat mit dem Namen erstellt myFormat. Der Code erstellt dann einen MyNewObject , der in einem DataObject. Die DataObject Datei wird in die ClipboardDatei kopiert.

Als Nächstes wird der DataObject Abruf aus dem Clipboard und dem MyNewObject wiederhergestellt. Der Wert der MyNewObject Zeichenfolge wird in einem Textfeld gedruckt. Für diesen Code muss ein textBox1 Formular erstellt und platziert werden.

#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>

using namespace System;
using namespace System::Windows::Forms;

// Creates a new type.

[Serializable]
public ref class MyNewObject: public Object
{
private:
   String^ myValue;

public:

   // Creates a default constructor for the class.
   MyNewObject()
   {
      myValue = "This is the value of the class";
   }


   property String^ MyObjectValue 
   {

      // Creates a property to retrieve or set the value.
      String^ get()
      {
         return myValue;
      }

      void set( String^ value )
      {
         myValue = value;
      }

   }

};

public ref class MyClass: public Form
{
protected:
   TextBox^ textBox1;

public:
   void MyClipboardMethod()
   {
      
      // Creates a new data format.
      DataFormats::Format^ myFormat = DataFormats::GetFormat( "myFormat" );
      
      /* Creates a new object and stores it in a DataObject using myFormat 
               * as the type of format. */
      MyNewObject^ myObject = gcnew MyNewObject;
      DataObject^ myDataObject = gcnew DataObject( myFormat->Name,myObject );
      
      // Copies myObject into the clipboard.
      Clipboard::SetDataObject( myDataObject );
      
      // Performs some processing steps.
      // Retrieves the data from the clipboard.
      IDataObject^ myRetrievedObject = Clipboard::GetDataObject();
      
      // Converts the IDataObject type to MyNewObject type. 
      MyNewObject^ myDereferencedObject = dynamic_cast<MyNewObject^>(myRetrievedObject->GetData( myFormat->Name ));
      
      // Prints the value of the Object in a textBox.
      textBox1->Text = myDereferencedObject->MyObjectValue;
   }

};
using System;
using System.Windows.Forms;

public class MyClass : Form {
    protected TextBox textBox1;
    
    public void MyClipboardMethod() {
       // Creates a new data format.
       DataFormats.Format myFormat = DataFormats.GetFormat("myFormat");
       
       /* Creates a new object and stores it in a DataObject using myFormat 
        * as the type of format. */
       MyNewObject myObject = new MyNewObject();
       DataObject myDataObject = new DataObject(myFormat.Name, myObject);
 
       // Copies myObject into the clipboard.
       Clipboard.SetDataObject(myDataObject);
 
       // Performs some processing steps.
 
       // Retrieves the data from the clipboard.
       IDataObject myRetrievedObject = Clipboard.GetDataObject();
 
       // Converts the IDataObject type to MyNewObject type. 
       MyNewObject myDereferencedObject = (MyNewObject)myRetrievedObject.GetData(myFormat.Name);
 
       // Prints the value of the Object in a textBox.
       textBox1.Text = myDereferencedObject.MyObjectValue;
    }
 }
 
 // Creates a new type.
 [Serializable]
 public class MyNewObject : Object {
    private string myValue;
 
    // Creates a default constructor for the class.
    public MyNewObject() {
       myValue = "This is the value of the class";
    }
 
    // Creates a property to retrieve or set the value.
    public string MyObjectValue {
       get {
          return myValue;
       }
       set {
          myValue = value;
       }
    }
 }
Option Explicit
Option Strict

Imports System.Windows.Forms

Public Class MyClass1
    Inherits Form
    Private textBox1 As TextBox

    Public Sub MyClipboardMethod()
        ' Creates a new data format.
        Dim myFormat As DataFormats.Format = _
            DataFormats.GetFormat("myFormat")
        
        ' Creates a new object and store it in a DataObject using myFormat 
        ' as the type of format. 
        Dim myObject As New MyNewObject()
        Dim myDataObject As New DataObject(myFormat.Name, myObject)
        
        ' Copies myObject into the clipboard.
        Clipboard.SetDataObject(myDataObject)
        
        ' Performs some processing steps.
        ' Retrieves the data from the clipboard.
        Dim myRetrievedObject As IDataObject = Clipboard.GetDataObject()
        
        ' Converts the IDataObject type to MyNewObject type. 
        Dim myDereferencedObject As MyNewObject = _
            CType(myRetrievedObject.GetData(myFormat.Name), MyNewObject)
        
        ' Print the value of the Object in a textBox.
        textBox1.Text = myDereferencedObject.MyObjectValue
    End Sub
End Class


' Creates a new type.
<Serializable()> Public Class MyNewObject
    Inherits Object
    Private myValue As String
    
    
    ' Creates a default constructor for the class.
    Public Sub New()
        myValue = "This is the value of the class"
    End Sub
    
    ' Creates a property to retrieve or set the value.
    
    Public Property MyObjectValue() As String
        Get
            Return myValue
        End Get
        Set
            myValue = value
        End Set
    End Property
End Class

Hinweise

Die IDataObject Klassen DataObject und Klassen verwenden auch die static Formatliste, um den Datentyp zu bestimmen, der aus dem System Clipboardabgerufen wird oder die in einem Drag-and-Drop-Vorgang übertragen wird.

Die GetFormat Methode ermöglicht Folgendes:

  • Rufen Sie ein vordefiniertes DataFormats.Format Objekt für einen Formatnamen oder eine ID-Nummer ab.

  • Fügen Sie der Liste static in dieser Klasse ein neues Formatnamen/ID-Nummernpaar hinzu, und registrieren Sie das Format bei der Windows Registrierung als Clipboard Format, wenn Sie ihn an den Formatnamen übergeben.

Sie können die Zahl oder das Id Format Name aus der entsprechenden Eigenschaft in der DataFormats.Format Instanz abrufen.

Felder

Name Beschreibung
Bitmap

Gibt ein Windows Bitmapformat an. Dieses static Feld ist schreibgeschützt.

CommaSeparatedValue

Gibt ein CSV-Format (Kommagetrennte Werte) an, bei dem es sich um ein gängiges Austauschformat handelt, das von Kalkulationstabellen verwendet wird. Dieses Format wird nicht direkt von Windows Forms verwendet. Dieses static Feld ist schreibgeschützt.

Dib

Gibt das Windows geräteunabhängigen Bitmapformat (DIB) an. Dieses static Feld ist schreibgeschützt.

Dif

Gibt das Windows Data Interchange Format (DIF) an, das Windows Forms nicht direkt verwendet. Dieses static Feld ist schreibgeschützt.

EnhancedMetafile

Gibt das erweiterte Metadateiformat Windows an. Dieses static Feld ist schreibgeschützt.

FileDrop

Gibt das Windows Dateiformat an, das Windows Forms nicht direkt verwendet. Dieses static Feld ist schreibgeschützt.

Html

Gibt Text im HTML-Zwischenablageformat an. Dieses static Feld ist schreibgeschützt.

Locale

Gibt das Windows Kulturformat an, das Windows Forms nicht direkt verwendet. Dieses static Feld ist schreibgeschützt.

MetafilePict

Gibt das Windows Metadateiformat an, das Windows Forms nicht direkt verwendet. Dieses static Feld ist schreibgeschützt.

OemText

Gibt das Standardtextformat Windows Originalgerätehersteller (OEM) an. Dieses static Feld ist schreibgeschützt.

Palette

Gibt das Windows Palettenformat an. Dieses static Feld ist schreibgeschützt.

PenData

Gibt das Windows Stiftdatenformat an, das aus Stiftstrichen für Handschriftsoftware besteht; Windows Forms verwendet dieses Format nicht. Dieses static Feld ist schreibgeschützt.

Riff

Gibt das RIFF-Audioformat (Resource Interchange File Format) an, das Windows Forms nicht direkt verwendet. Dieses static Feld ist schreibgeschützt.

Rtf

Gibt Text an, der aus RTF-Daten (Rich Text Format) besteht. Dieses static Feld ist schreibgeschützt.

Serializable

Gibt ein Format an, das einen beliebigen Typ von Windows Forms-Objekt kapselt. Dieses static Feld ist schreibgeschützt.

StringFormat

Gibt das Windows Forms Zeichenfolgenklassenformat an, das Windows Forms zum Speichern von Zeichenfolgenobjekten verwendet. Dieses static Feld ist schreibgeschützt.

SymbolicLink

Gibt das Windows symbolische Verknüpfungsformat an, das Windows Forms nicht direkt verwendet. Dieses static Feld ist schreibgeschützt.

Text

Gibt das standardmäßige ANSI-Textformat an. Dieses static Feld ist schreibgeschützt.

Tiff

Gibt das Tagged Image File Format (TIFF) an, das Windows Forms nicht direkt verwendet. Dieses static Feld ist schreibgeschützt.

UnicodeText

Gibt das Standardmäßige Windows Unicode-Textformat an. Dieses static Feld ist schreibgeschützt.

WaveAudio

Gibt das Wellenaudioformat an, das Windows Forms nicht direkt verwendet. Dieses static Feld ist schreibgeschützt.

Methoden

Name Beschreibung
Equals(Object)

Bestimmt, ob das angegebene Objekt gleich dem aktuellen Objekt ist.

(Geerbt von Object)
GetFormat(Int32)

Gibt eine DataFormats.Format mit der numerischen WINDOWS-ID der Zwischenablage und dem Namen für die angegebene ID zurück.

GetFormat(String)

Gibt eine DataFormats.Format mit der numerischen WINDOWS-ID und dem Namen der Zwischenablage für das angegebene Format zurück.

GetHashCode()

Dient als Standardhashfunktion.

(Geerbt von Object)
GetType()

Ruft die Type der aktuellen Instanz ab.

(Geerbt von Object)
MemberwiseClone()

Erstellt eine flache Kopie der aktuellen Object.

(Geerbt von Object)
ToString()

Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt.

(Geerbt von Object)

Gilt für:

Weitere Informationen