Export (0) Print
Expand All

Clipboard.GetDataObject Method

Retrieves the data that is currently on the system Clipboard.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

static member GetDataObject : unit -> IDataObject

Return Value

Type: System.Windows.Forms.IDataObject
An IDataObject that represents the data currently on the Clipboard, or a null reference (Nothing in Visual Basic) if there is no data on the Clipboard.

ExceptionCondition
ExternalException

Data could not be retrieved from the Clipboard. This typically occurs when the Clipboard is being used by another process.

ThreadStateException

The current thread is not in single-threaded apartment (STA) mode and the Application.MessageLoop property value is true. Add the STAThreadAttribute to your application's Main method.

Because the data type of the object returned from the Clipboard can vary, this method returns the data in an IDataObject. Then you can use methods of the IDataObject interface to extract the data in its proper data type.

This method attempts to get the data ten times in 100-millisecond intervals, and throws an ExternalException if all attempts are unsuccessful.

NoteNote

The 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.

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 placed on the form.

The button1_Click method calls SetDataObject to take selected text from the text box and place it on the system Clipboard.

The button2_Click method calls GetDataObject to retrieve data from the system Clipboard. The code uses IDataObject and DataFormats to extract the data returned. The data is displayed in textBox2.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft