本文整理匯總了C#中System.Windows.Forms.DataFormats類的典型用法代碼示例。如果您正苦於以下問題:C# DataFormats類的具體用法?C# DataFormats怎麽用?C# DataFormats使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DataFormats類屬於System.Windows.Forms命名空間,在下文中一共展示了DataFormats類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: MyClipboardMethod
//引入命名空間
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;
}
}
}