DataFormats 类

定义

提供 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
继承
DataFormats

示例

下面的代码示例创建一个名为 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 复制到 ClipboardThe DataObject is copied to the Clipboard.

接下来,从 Clipboard 中检索 DataObject,并恢复 MyNewObjectNext, 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

注解

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

GetFormat 方法使你能够:The GetFormat method allows you to:

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

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

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

字段

Bitmap

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

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

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

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

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

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 剪贴板格式中的文本。Specifies text in the HTML Clipboard format. static 字段是只读的。This static field is read-only.

Locale

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

MetafilePict

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

OemText

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

Palette

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

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) 音频格式,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 数据组成的文本。Specifies text consisting of Rich Text Format (RTF) data. static 字段是只读的。This static field is read-only.

Serializable

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

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

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

Text

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

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

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

WaveAudio

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

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetFormat(Int32)

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

GetFormat(String)

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

GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

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

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

适用于

另请参阅