DataFormats Classe
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Fornisce staticnomi di formato predefiniti Clipboard . Usarli per identificare il formato dei dati archiviati in un oggetto IDataObject.
public ref class DataFormats
public 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 oggetto DataObject. L'oggetto DataObject viene copiato nell'oggetto Clipboard.
DataObject Viene quindi recuperato da Clipboard e viene MyNewObject recuperato . Il valore di 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 della selezione.
Il GetFormat metodo consente di:
Ottenere un oggetto predefinito DataFormats.Format per un nome di formato o un numero ID.
Aggiungere una nuova coppia nome formato/numero ID all'elenco
staticin questa classe e registrare il formato con il Registro di sistema Windows come formato Clipboard quando si passa il nome del formato.
È possibile ottenere il numero o il Id formato Name dalla proprietà appropriata nell'istanza DataFormats.Format di .
Campi
| Nome | Descrizione |
|---|---|
| Bitmap |
Specifica un formato bitmap Windows. Questo |
| CommaSeparatedValue |
Specifica un formato con valori delimitati da virgole (CSV), ovvero un formato di interscambio comune usato dai fogli di calcolo. Questo formato non viene utilizzato direttamente da Windows Forms. Questo |
| Dib |
Specifica il formato bitmap indipendente dal dispositivo (DIB) Windows. Questo |
| Dif |
Specifica il formato DIF (Data Interchange Format) di Windows, che Windows Forms non viene usato direttamente. Questo |
| EnhancedMetafile |
Specifica il formato del metafile avanzato Windows. Questo |
| FileDrop |
Specifica il formato di rilascio del file Windows, che Windows Forms non usa direttamente. Questo |
| Html |
Specifica il testo nel formato Degli Appunti HTML. Questo |
| Locale |
Specifica il formato delle impostazioni cultura Windows, che Windows Forms non usa direttamente. Questo |
| MetafilePict |
Specifica il formato metafile Windows, che Windows Forms non usa direttamente. Questo |
| OemText |
Specifica il formato di testo OEM (Original Equipment Manufacturer) standard Windows. Questo |
| Palette |
Specifica il formato della tavolozza Windows. Questo |
| PenData |
Specifica il formato di dati della penna Windows, costituito da tratti della penna per il software di scrittura manuale; Windows Forms non usa questo formato. Questo |
| Riff |
Specifica il formato audio RIFF (Resource Interchange File Format), che Windows Forms non usa direttamente. Questo |
| Rtf |
Specifica il testo costituito da dati RTF (Rich Text Format). Questo |
| Serializable |
Specifica un formato che incapsula qualsiasi tipo di oggetto Windows Forms. Questo |
| StringFormat |
Specifica il formato della classe stringa Windows Forms, che Windows Forms usa per archiviare oggetti stringa. Questo |
| SymbolicLink |
Specifica il formato di collegamento simbolico Windows, che Windows Forms non usa direttamente. Questo |
| Text |
Specifica il formato di testo ANSI standard. Questo |
| Tiff |
Specifica il formato TIFF (Tagged Image File Format), che Windows Forms non usa direttamente. Questo |
| UnicodeText |
Specifica il formato di testo Unicode Windows standard. Questo |
| WaveAudio |
Specifica il formato audio dell'onda, che Windows Forms non usa direttamente. Questo |
Metodi
| Nome | Descrizione |
|---|---|
| Equals(Object) |
Determina se l'oggetto specificato è uguale all'oggetto corrente. (Ereditato da Object) |
| GetFormat(Int32) |
Restituisce un DataFormats.Format con l'ID numerico degli Appunti Windows e il nome per l'ID specificato. |
| GetFormat(String) |
Restituisce un DataFormats.Format con l'ID numerico degli Appunti Windows e il nome per il formato specificato. |
| GetHashCode() |
Funge da funzione hash predefinita. (Ereditato da Object) |
| GetType() |
Ottiene il Type dell'istanza corrente. (Ereditato da Object) |
| MemberwiseClone() |
Crea una copia superficiale del Objectcorrente. (Ereditato da Object) |
| ToString() |
Restituisce una stringa che rappresenta l'oggetto corrente. (Ereditato da Object) |