NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Clipboard.GetDataObject

Retrieves the data that is currently on the system Clipboard.

[Visual Basic]
Public Shared Function GetDataObject() As IDataObject
[C#]
public static IDataObject GetDataObject();
[C++]
public: static IDataObject* GetDataObject();
[JScript]
public static function GetDataObject() : IDataObject;

Return Value

An IDataObject that represents data currently on the Clipboard.

Exceptions

Exception Type Condition
Exception Data could not be placed on the Clipboard. The exception can occur because another application has the Clipboard open.

Example [Visual Basic]

The following 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 and displays the data in TextBox2.

[Visual Basic]

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
   'Take the selected text from a text box and put it on the clipboard.
   Clipboard.SetDataObject(TextBox1.SelectedText)
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
   'Declare an IDataObject to hold the data returned from the clipboard.
   'Then retrieve the data from the clipboard.
   Dim iData As IDataObject
   iData = Clipboard.GetDataObject

   'Determine whether the data is in a format you can use.
   If iData.GetDataPresent(DataFormats.Text) Then
      'Yes it is, so display it in a text box.
      TextBox2.Text = iData.GetData(DataFormats.Text).ToString
   Else
      'No it is not.
      TextBox2.Text = "Could not retrieve data off the clipboard."
   End If
End Sub

See Also

Clipboard Class | Clipboard Members | System.WinForms Namespace | DataObject | DataFormats | SetDataObject | IDataObject