DataFormats Classe

Definizione

Fornisce nomi di formato Clipboard predefiniti e static. Utilizzare questi nomi per identificare il formato dei dati memorizzati in un IDataObject.

public ref class DataFormats
public ref class DataFormats abstract sealed
public class DataFormats
public static class DataFormats
type DataFormats = class
Public Class DataFormats
Ereditarietà
DataFormats

Esempio

Nell'esempio di codice seguente viene creato un nuovo formato di dati denominato myFormat. Il codice crea quindi un oggetto MyNewObject che archivia in un DataObjectoggetto . L'oggetto DataObject viene copiato nell'oggetto Clipboard.

Successivamente, l'oggetto DataObject viene recuperato dall'oggetto Clipboard e viene MyNewObject recuperato. Il valore dell'oggetto MyNewObject viene stampato in una casella di testo. Questo codice richiede che textBox1 sia stato creato e inserito in un modulo.

#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

Commenti

Le IDataObject classi e DataObject usano anche l'elenco static di formati per determinare il tipo di dati recuperati dal sistema Clipboardo trasferiti in un'operazione di trascinamento.

Il GetFormat metodo consente di:

  • Ottenere un oggetto predefinito DataFormats.Format per un nome di formato o un numero ID.

  • Aggiungere una nuova coppia di nomi di formato/NUMERO ID all'elenco static in questa classe e per registrare il formato con il Registro di sistema di Windows come Clipboard formato quando si passa il nome del formato.

È possibile ottenere il numero o il Id formato Name dalla proprietà appropriata nell'istanza DataFormats.Format .

Campi

Bitmap

Specifica un formato di bitmap Windows. Questo campo static è di sola lettura.

CommaSeparatedValue

Specifica un formato con valori separati da virgola (CSV), ovvero un formato di interscambio comune utilizzato dai fogli di calcolo. Il formato non viene utilizzato direttamente da Windows Form. Questo campo static è di sola lettura.

Dib

Specifica il formato DIB (Device Independent Bitmap, bitmap indipendente dalla periferica) di Windows. Questo campo static è di sola lettura.

Dif

Specifica il formato DIF (Data Interchange Format, formato di interscambio dati) di Windows, non utilizzato direttamente da Windows Form. Questo campo static è di sola lettura.

EnhancedMetafile

Specifica il formato metafile avanzato di Windows. Questo campo static è di sola lettura.

FileDrop

Specifica il formato di trascinamento dei file di Windows, non utilizzato direttamente da Windows Form. Questo campo static è di sola lettura.

Html

Specifica il testo nel formato HTML degli Appunti. Questo campo static è di sola lettura.

Locale

Specifica il formato delle impostazioni cultura di Windows, non utilizzato direttamente da Windows Form. Questo campo static è di sola lettura.

MetafilePict

Specifica il formato metafile di Windows, non utilizzato direttamente da Windows Form. Questo campo static è di sola lettura.

OemText

Specifica il formato di testo standard OEM (Original Equipment Manufacturer) di Windows. Questo campo static è di sola lettura.

Palette

Specifica il formato tavolozza di Windows. Questo campo static è di sola lettura.

PenData

Specifica il formato di dati penna di Windows, composto da tratti di penna per il software di scrittura; Windows Form non utilizza questo formato. Questo campo static è di sola lettura.

Riff

Specifica il formato audio di interscambio RIFF (Resource Interchange File Format), non utilizzato direttamente da Windows Form. Questo campo static è di sola lettura.

Rtf

Specifica il testo costituito di dati RTF (Rich Text Format). Questo campo static è di sola lettura.

Serializable

Specifica un formato che incapsula ogni tipo di oggetto Windows Form. Questo campo static è di sola lettura.

StringFormat

Specifica il formato della classe string di Windows Form, utilizzato per memorizzare gli oggetti string. Questo campo static è di sola lettura.

SymbolicLink

Specifica il formato del collegamento simbolico di Windows, non utilizzato direttamente da Windows Form. Questo campo static è di sola lettura.

Text

Specifica il formato di testo ANSI standard. Questo campo static è di sola lettura.

Tiff

Specifica il formato TIFF (Tagged Image File Format), non utilizzato direttamente da Windows Form. Questo campo static è di sola lettura.

UnicodeText

Specifica il formato di testo Unicode standard di Windows. Questo campo static è di sola lettura.

WaveAudio

Specifica il formato audio wave, non utilizzato direttamente da Windows Form. Questo campo static è di sola lettura.

Metodi

GetFormat(Int32)

Restituisce un oggetto DataFormats.Format con l'ID numerico degli Appunti di Windows e il nome per l'ID specificato.

GetFormat(String)

Restituisce un oggetto DataFormats.Format con il nome e l'ID numerico degli Appunti di Windows per il formato specificato.

Si applica a

Vedi anche