O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

Clipboard.GetDataObject Method

Class

System.Windows.Forms.Clipboard

Syntax

Clipboard.GetDataObject(  )

Return value

An IDataObject object that represents the data currently on the clipboard

Description

Retrieves data from the Clipboard

Rules at a Glance

  • If the Clipboard contains no data, the GetDataObject method returns Nothing.

  • Once you have an IDataObject object, you can use the members of the IDataObject class to get information about the Clipboard data, as shown in the following example. The relevant IDataObject members for Clipboard manipulation in VB are GetData, GetDataPresent, and GetFormats.

Example

The following example extracts the text that is currently on the Clipboard:

' Declare IDataObject variable and get clipboard IDataObject
Dim di As IDataObject = Clipboard.GetDataObject

Dim obj As Object

' Fire GetData method of IDataObject object to get clipboard data
obj = di.GetData(DataFormats.Text, False)

' Show the text, if any
If obj Is Nothing Then
   MsgBox("No text on clipboard.")
Else
   MsgBox(CStr(obj))
End If

VB.NET/VB 6 Differences

While the .NET Base Class Library uses the GetDataObject method to retrieve all data from the Clipboard, the Clipboard object in VB 6 included the GetFormat, GetData, and GetText methods to retrieve Clipboard data.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required