DataFormats DataFormats DataFormats DataFormats Class

Definition

Provides static, predefined Clipboard format names. Use them to identify the format of data that you store in an IDataObject.

public ref class DataFormats
public class DataFormats
type DataFormats = class
Public Class DataFormats
Inheritance
DataFormatsDataFormatsDataFormatsDataFormats

Examples

The following code example creates a new data format named myFormat. The code then creates a MyNewObject which it stores in a DataObject. The DataObject is copied to the Clipboard.

Next, the DataObject is retrieved from the Clipboard and the MyNewObject is recovered. The value of the MyNewObject is printed in a text box. This code requires that textBox1 has been created and placed on a form.

#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
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 'MyClipboardMethod
End Class 'MyClass


' 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 'New
    
    ' 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 'MyNewObject

Remarks

The IDataObject and DataObject classes also use the static format list to determine the type of data that is retrieved from the system Clipboard, or that is transferred in a drag-and-drop operation.

The GetFormat method allows you to:

  • Get a predefined DataFormats.Format object for a format name or ID number.

  • Add a new format name/ID number pair to the static list in this class, and to register the format with the Windows registry as a Clipboard format when you pass it the format name.

You can get the Id number or format Name from the appropriate property in the DataFormats.Format instance.

Fields

Bitmap Bitmap Bitmap Bitmap

Specifies a Windows bitmap format. This static field is read-only.

CommaSeparatedValue CommaSeparatedValue CommaSeparatedValue CommaSeparatedValue

Specifies a comma-separated value (CSV) format, which is a common interchange format used by spreadsheets. This format is not used directly by Windows Forms. This static field is read-only.

Dib Dib Dib Dib

Specifies the Windows device-independent bitmap (DIB) format. This static field is read-only.

Dif Dif Dif Dif

Specifies the Windows Data Interchange Format (DIF), which Windows Forms does not directly use. This static field is read-only.

EnhancedMetafile EnhancedMetafile EnhancedMetafile EnhancedMetafile

Specifies the Windows enhanced metafile format. This static field is read-only.

FileDrop FileDrop FileDrop FileDrop

Specifies the Windows file drop format, which Windows Forms does not directly use. This static field is read-only.

Html Html Html Html

Specifies text in the HTML Clipboard format. This static field is read-only.

Locale Locale Locale Locale

Specifies the Windows culture format, which Windows Forms does not directly use. This static field is read-only.

MetafilePict MetafilePict MetafilePict MetafilePict

Specifies the Windows metafile format, which Windows Forms does not directly use. This static field is read-only.

OemText OemText OemText OemText

Specifies the standard Windows original equipment manufacturer (OEM) text format. This static field is read-only.

Palette Palette Palette Palette

Specifies the Windows palette format. This static field is read-only.

PenData PenData PenData PenData

Specifies the Windows pen data format, which consists of pen strokes for handwriting software; Windows Forms does not use this format. This static field is read-only.

Riff Riff Riff Riff

Specifies the Resource Interchange File Format (RIFF) audio format, which Windows Forms does not directly use. This static field is read-only.

Rtf Rtf Rtf Rtf

Specifies text consisting of Rich Text Format (RTF) data. This static field is read-only.

Serializable Serializable Serializable Serializable

Specifies a format that encapsulates any type of Windows Forms object. This static field is read-only.

StringFormat StringFormat StringFormat StringFormat

Specifies the Windows Forms string class format, which Windows Forms uses to store string objects. This static field is read-only.

SymbolicLink SymbolicLink SymbolicLink SymbolicLink

Specifies the Windows symbolic link format, which Windows Forms does not directly use. This static field is read-only.

Text Text Text Text

Specifies the standard ANSI text format. This static field is read-only.

Tiff Tiff Tiff Tiff

Specifies the Tagged Image File Format (TIFF), which Windows Forms does not directly use. This static field is read-only.

UnicodeText UnicodeText UnicodeText UnicodeText

Specifies the standard Windows Unicode text format. This static field is read-only.

WaveAudio WaveAudio WaveAudio WaveAudio

Specifies the wave audio format, which Windows Forms does not directly use. This static field is read-only.

Methods

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetFormat(Int32) GetFormat(Int32) GetFormat(Int32) GetFormat(Int32)

Returns a DataFormats.Format with the Windows Clipboard numeric ID and name for the specified ID.

GetFormat(String) GetFormat(String) GetFormat(String) GetFormat(String)

Returns a DataFormats.Format with the Windows Clipboard numeric ID and name for the specified format.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

See also