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
IDataObjectobject, 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 IfVB.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.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access