本文整理汇总了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;
}
}
}