System.Windows.Forms.Clipboard Class

Provides methods to place data on and retrieve data from the system Clipboard. This class cannot be inherited.

See Also: Clipboard Members


public sealed class Clipboard


For a list of predefined formats to use with the System.Windows.Forms.Clipboard class, see the System.Windows.Forms.DataFormats class.

Call Clipboard.SetDataObject(object) to put data on the Clipboard, replacing its current contents. To place a persistent copy of the data on the Clipboard, set the copy parameter to true.


To place data on the Clipboard in multiple formats, use the System.Windows.Forms.DataObject class or an System.Windows.Forms.IDataObject implementation. Place data on the Clipboard in multiple formats to maximize the possibility that a target application, whose format requirements you might not know, can successfully retrieve the data.

Call Clipboard.GetDataObject to retrieve data from the Clipboard. The data is returned as an object that implements the System.Windows.Forms.IDataObject interface. Use the methods specified by System.Windows.Forms.IDataObject and fields in System.Windows.Forms.DataFormats to extract the data from the object. If you do not know the format of the data you retrieved, call the IDataObject.GetFormats(bool) method of the System.Windows.Forms.IDataObject interface to get a list of all formats that data is stored in. Then call the IDataObject.GetData(string, bool) method of the System.Windows.Forms.IDataObject interface, and specify a format that your application can use.

In dnprdnext, the System.Windows.Forms.Clipboard class provides additional methods that make it easier to work with the system Clipboard. Call the Clipboard.Clear method to remove all data from the Clipboard. To add data of a particular format to the Clipboard, replacing the existing data, call the appropriate SetFormat method, such as erload:System.Windows.Forms.Clipboard.SetText, or call the Clipboard.SetData(string, object) method to specify the format. To retrieve data of a particular format from the Clipboard, first call the appropriate ContainsFormat method (such as erload:System.Windows.Forms.Clipboard.ContainsText) method to determine whether the Clipboard contains data in that format, and then call the appropriate GetFormat method (such as erload:System.Windows.Forms.Clipboard.GetText) to retrieve the data if the Clipboard contains it. To specify the format in these operations, call the Clipboard.ContainsData(string) and Clipboard.GetData(string) methods instead.


All Windows-based applications share the system Clipboard, so the contents are subject to change when you switch to another application.

An object must be serializable for it to be put on the Clipboard. If you pass a non-serializable object to a Clipboard method, the method will fail without throwing an exception. See System.Runtime.Serialization for more information on serialization. If your target application requires a very specific data format, the headers added to the data in the serialization process may prevent the application from recognizing your data. To preserve your data format, add your data as a byte array to a System.IO.MemoryStream and pass the System.IO.MemoryStream to the DataObject.SetData(object) method.

The System.Windows.Forms.Clipboard class can only be used in threads set to single thread apartment (STA) mode. To use this class, ensure that your Main method is marked with the STAThreadAttribute attribute.

Special considerations may be necessary when using the metafile format with the Clipboard. Due to a limitation in the current implementation of the System.Windows.Forms.DataObject class, the metafile format used by the .NET Framework may not be recognized by applications that use an older metafile format. In this case, you must interoperate with the Win32 Clipboard application programming interfaces (APIs). For more information, see article 323530, "Metafiles on Clipboard Are Not Visible to All Applications," in the Microsoft Knowledge Base at


Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 1.0.5000.0,