System.windows.forms.clipboard
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support. Feedback will be sent to Microsoft: By pressing the submit button, your feedback will be used to improve Microsoft products and services. Privacy policy. Thank you. Microsoft makes no warranties, express or implied, with respect to the information provided here. Provides methods to place data on and retrieve data from the system Clipboard.
This class cannot be inherited. The following code example uses Clipboard methods to place data on and retrieve it from the system Clipboard. This code assumes button1 , button2 , textBox1 , and textBox2 have been created and placed on the form.
For a list of predefined formats to use with the Clipboard class, see the DataFormats class. Call SetDataObject 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. 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 GetDataObject to retrieve data from the Clipboard. The data is returned as an object that implements the IDataObject interface. Use the methods specified by IDataObject and fields in DataFormats to extract the data from the object.
If you do not know the format of the data you retrieved, call the GetFormats method of the IDataObject interface to get a list of all formats that data is stored in. Then call the GetData method of the IDataObject interface, and specify a format that your application can use.
NET Framework 2. Call the 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 Set Format method, such as SetText , or call the SetData method to specify the format. To retrieve data of a particular format from the Clipboard, first call the appropriate Contains Format method such as ContainsText method to determine whether the Clipboard contains data in that format, and then call the appropriate Get Format method such as GetText to retrieve the data if the Clipboard contains it.
To specify the format in these operations, call the ContainsData and GetData methods instead. All Windows-based applications share the system Clipboard, so the contents are subject to change when you switch to another application.
This method attempts to get the data ten times in millisecond intervals, and throws an ExternalException if all attempts are unsuccessful. The Clipboard class can only be used in threads set to single thread apartment STA mode.
Skip to main content. This browser is no longer supported. Download Microsoft Edge More info. Contents Exit focus mode. Please rate your experience Yes No. Any additional feedback?
To retrieve text data from the Clipboard, first use the ContainsText method to determine whether the Clipboard contains text data before retrieving it with the GetText method. The Clipboard class can only be used in threads set to single thread apartment STA mode.
One of the TextDataFormat values. Skip to main content. This browser is no longer supported. Download Microsoft Edge More info. Contents Exit focus mode. Set Text Method Reference Is this page helpful? Please rate your experience Yes No.