DataFormats Classe

Définition

Fournit staticdes noms de format prédéfinis Clipboard . Utilisez-les pour identifier le format des données que vous stockez dans un IDataObject.

public ref class DataFormats
public class DataFormats
type DataFormats = class
Public Class DataFormats
Héritage
DataFormats

Exemples

L’exemple de code suivant crée un format de données nommé myFormat. Le code crée ensuite un MyNewObject fichier qu’il stocke dans un DataObject. Le DataObject fichier est copié dans le Clipboard.

Ensuite, l’élément DataObject est récupéré à partir de celui-ci Clipboard et celui-ci MyNewObject est récupéré. La valeur de l’objet MyNewObject est imprimée dans une zone de texte. Ce code nécessite la textBox1 création et l’ajout d’un formulaire.

#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

Remarques

Les IDataObject classes et DataObject les classes utilisent également la static liste de formats pour déterminer le type de données récupérées à partir du système Clipboardou transférées dans une opération de glisser-déplacer.

La GetFormat méthode vous permet de :

  • Obtenir un objet prédéfini DataFormats.Format pour un nom de format ou un numéro d’ID.

  • Ajoutez une nouvelle paire de noms de format/numéro d’ID à la liste static dans cette classe et inscrivez le format auprès du registre Windows en tant que format Clipboard lorsque vous passez le nom du format.

Vous pouvez obtenir le nombre ou le Id format Name à partir de la propriété appropriée dans l’instance DataFormats.Format .

Champs

Nom Description
Bitmap

Spécifie un format bitmap Windows. Ce static champ est en lecture seule.

CommaSeparatedValue

Spécifie un format de valeur séparée par des virgules (CSV), qui est un format d’échange commun utilisé par les feuilles de calcul. Ce format n’est pas utilisé directement par Windows Forms. Ce static champ est en lecture seule.

Dib

Spécifie le format bitmap indépendant de l’appareil (DIB) Windows. Ce static champ est en lecture seule.

Dif

Spécifie le Windows format d’échange de données (DIF), qui Windows Forms n’utilise pas directement. Ce static champ est en lecture seule.

EnhancedMetafile

Spécifie le format de métafichier amélioré Windows. Ce static champ est en lecture seule.

FileDrop

Spécifie le format de suppression de fichier Windows, qui Windows Forms n’utilise pas directement. Ce static champ est en lecture seule.

Html

Spécifie du texte au format Html Presse-papiers. Ce static champ est en lecture seule.

Locale

Spécifie le format de culture Windows, qui Windows Forms n’utilise pas directement. Ce static champ est en lecture seule.

MetafilePict

Spécifie le format de métafichier Windows, qui Windows Forms n’utilise pas directement. Ce static champ est en lecture seule.

OemText

Spécifie le format de texte standard Windows fabricant d’équipement d’origine (OEM). Ce static champ est en lecture seule.

Palette

Spécifie le format de palette Windows. Ce static champ est en lecture seule.

PenData

Spécifie le format de données de stylet Windows, qui se compose de traits de stylet pour le logiciel d’écriture manuscrite ; Windows Forms n’utilise pas ce format. Ce static champ est en lecture seule.

Riff

Spécifie le format audio RIFF (Resource Interchange File Format), qui Windows Forms n’utilise pas directement. Ce static champ est en lecture seule.

Rtf

Spécifie le texte constitué de données RTF (Rich Text Format). Ce static champ est en lecture seule.

Serializable

Spécifie un format qui encapsule tout type d’objet Windows Forms. Ce static champ est en lecture seule.

StringFormat

Spécifie le format de classe de chaîne Windows Forms, que Windows Forms utilise pour stocker des objets de chaîne. Ce static champ est en lecture seule.

SymbolicLink

Spécifie le format de lien symbolique Windows, qui Windows Forms n’utilise pas directement. Ce static champ est en lecture seule.

Text

Spécifie le format de texte ANSI standard. Ce static champ est en lecture seule.

Tiff

Spécifie le format TIFF (Tagged Image File Format), qui Windows Forms n’utilise pas directement. Ce static champ est en lecture seule.

UnicodeText

Spécifie le format de texte Unicode standard Windows. Ce static champ est en lecture seule.

WaveAudio

Spécifie le format audio wave, qui Windows Forms n’utilise pas directement. Ce static champ est en lecture seule.

Méthodes

Nom Description
Equals(Object)

Détermine si l’objet spécifié est égal à l’objet actuel.

(Hérité de Object)
GetFormat(Int32)

Retourne un DataFormats.Format avec l’ID numérique Windows Presse-papiers et le nom de l’ID spécifié.

GetFormat(String)

Retourne un DataFormats.Format avec l’ID numérique Windows Presse-papiers et le nom du format spécifié.

GetHashCode()

Sert de fonction de hachage par défaut.

(Hérité de Object)
GetType()

Obtient la Type de l’instance actuelle.

(Hérité de Object)
MemberwiseClone()

Crée une copie superficielle du Objectactuel.

(Hérité de Object)
ToString()

Retourne une chaîne qui représente l’objet actuel.

(Hérité de Object)

S’applique à

Voir aussi