DataFormats DataFormats DataFormats DataFormats Class

定义

提供 static 预定义的 Clipboard 格式名称。Provides static, predefined Clipboard format names. 使用它们来标识存储在 IDataObject 中的数据的格式。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
继承
DataFormatsDataFormatsDataFormatsDataFormats

示例

下面的代码示例创建一个名为myFormat的新数据格式。The following code example creates a new data format named myFormat. 然后, 该代码创建MyNewObject一个存储DataObject在中的。The code then creates a MyNewObject which it stores in a DataObject. DataObject将复制Clipboard到。The DataObject is copied to the Clipboard.

接下来, DataObject Clipboard从检索, 并MyNewObject恢复。Next, the DataObject is retrieved from the Clipboard and the MyNewObject is recovered. MyNewObject值将打印在文本框中。The value of the MyNewObject is printed in a text box. 此代码要求textBox1已创建并放置在窗体上。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.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

注解

和类还使用static格式列表来确定Clipboard从系统检索的数据类型, 或者在拖放操作中传输的数据的类型。 DataObject IDataObjectThe 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.

GetFormat方法允许您:The GetFormat method allows you to:

  • 获取格式名称DataFormats.Format或 ID 号的预定义的对象。Get a predefined DataFormats.Format object for a format name or ID number.

  • 在此类的static列表中添加一个新的格式名/ID 号对, 并在向其传递格式名称时, 使用 Windows 注册表将格式注册Clipboard为格式。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.

可以从Id 实例DataFormats.Format中的相应属性Name获取数字或格式。You can get the Id number or format Name from the appropriate property in the DataFormats.Format instance.

字段

Bitmap Bitmap Bitmap Bitmap

指定 Windows 位图格式。Specifies a Windows bitmap format. static 字段是只读的。This static field is read-only.

CommaSeparatedValue CommaSeparatedValue CommaSeparatedValue CommaSeparatedValue

指定以逗号分隔值 (CSV) 的格式,这是电子表格常用的交换格式。Specifies a comma-separated value (CSV) format, which is a common interchange format used by spreadsheets. Windows 窗体不直接使用此格式。This format is not used directly by Windows Forms. static 字段是只读的。This static field is read-only.

Dib Dib Dib Dib

指定 Windows 与设备无关的位图 (DIB) 格式。Specifies the Windows device-independent bitmap (DIB) format. static 字段是只读的。This static field is read-only.

Dif Dif Dif Dif

指定 Windows 数据交换格式 (DIF),Windows 窗体不直接使用此格式。Specifies the Windows Data Interchange Format (DIF), which Windows Forms does not directly use. static 字段是只读的。This static field is read-only.

EnhancedMetafile EnhancedMetafile EnhancedMetafile EnhancedMetafile

指定 Windows 增强型图元文件格式。Specifies the Windows enhanced metafile format. static 字段是只读的。This static field is read-only.

FileDrop FileDrop FileDrop FileDrop

指定 Windows 文件放置格式,Windows 窗体不直接使用此格式。Specifies the Windows file drop format, which Windows Forms does not directly use. static 字段是只读的。This static field is read-only.

Html Html Html Html

指定 HTML 剪贴板格式中的文本。Specifies text in the HTML Clipboard format. static 字段是只读的。This static field is read-only.

Locale Locale Locale Locale

指定 Windows 区域性格式,Windows 窗体不直接使用此格式。Specifies the Windows culture format, which Windows Forms does not directly use. static 字段是只读的。This static field is read-only.

MetafilePict MetafilePict MetafilePict MetafilePict

指定 Windows 图元文件格式,Windows 窗体不直接使用此格式。Specifies the Windows metafile format, which Windows Forms does not directly use. static 字段是只读的。This static field is read-only.

OemText OemText OemText OemText

指定标准 Windows 原始设备制造商 (OEM) 文本格式。Specifies the standard Windows original equipment manufacturer (OEM) text format. static 字段是只读的。This static field is read-only.

Palette Palette Palette Palette

指定 Windows 调色板格式。Specifies the Windows palette format. static 字段是只读的。This static field is read-only.

PenData PenData PenData PenData

指定 Windows 钢笔数据格式,它由书写软件所使用的笔画组成,Windows 窗体不使用此格式。Specifies the Windows pen data format, which consists of pen strokes for handwriting software; Windows Forms does not use this format. static 字段是只读的。This static field is read-only.

Riff Riff Riff Riff

指定资源交换文件格式 (RIFF) 音频格式,Windows 窗体不直接使用此格式。Specifies the Resource Interchange File Format (RIFF) audio format, which Windows Forms does not directly use. static 字段是只读的。This static field is read-only.

Rtf Rtf Rtf Rtf

指定由 RTF 数据组成的文本。Specifies text consisting of Rich Text Format (RTF) data. static 字段是只读的。This static field is read-only.

Serializable Serializable Serializable Serializable

指定封装任何类型的 Windows 窗体对象的格式。Specifies a format that encapsulates any type of Windows Forms object. static 字段是只读的。This static field is read-only.

StringFormat StringFormat StringFormat StringFormat

指定 Windows 窗体字符串类格式,Windows 窗体使用此格式存储字符串对象。Specifies the Windows Forms string class format, which Windows Forms uses to store string objects. static 字段是只读的。This static field is read-only.

SymbolicLink SymbolicLink SymbolicLink SymbolicLink

指定 Windows 符号链接格式,Windows 窗体不直接使用此格式。Specifies the Windows symbolic link format, which Windows Forms does not directly use. static 字段是只读的。This static field is read-only.

Text Text Text Text

指定标准 ANSI 文本格式。Specifies the standard ANSI text format. static 字段是只读的。This static field is read-only.

Tiff Tiff Tiff Tiff

指定标记图像文件格式 (TIFF),Windows 窗体不直接使用此格式。Specifies the Tagged Image File Format (TIFF), which Windows Forms does not directly use. static 字段是只读的。This static field is read-only.

UnicodeText UnicodeText UnicodeText UnicodeText

指定标准 Windows Unicode 文本格式。Specifies the standard Windows Unicode text format. static 字段是只读的。This static field is read-only.

WaveAudio WaveAudio WaveAudio WaveAudio

指定 wave 音频格式,Windows 窗体不直接使用此格式。Specifies the wave audio format, which Windows Forms does not directly use. static 字段是只读的。This static field is read-only.

方法

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)

为指定的 ID 返回带有 Windows 剪贴板数字 ID 和名称的 DataFormats.FormatReturns a DataFormats.Format with the Windows Clipboard numeric ID and name for the specified ID.

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

为指定的格式返回带有 Windows 剪贴板数字 ID 和名称的 DataFormats.FormatReturns 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()

获取当前实例的 TypeGets the Type of the current instance.

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

创建当前 Object 的浅表副本。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)

适用于

另请参阅