Use the Clipboard

Problem

You want to paste data to or retrieve data from the Windows clipboard.

Solution

Use the SetDataObject and GetDataObject methods of the System. Windows.Forms.Clipboard class.

Discussion

The System.Windows.Forms.Clipboard class allows you to place data on the Windows clipboard and retrieve it. You can use the Clipboard class in any type of application, from Windows programs to Console utilities (although you’ll need to add a reference to the System.Windows.Forms.dll assembly). Valid clipboard data includes core .NET types (strings, numbers, and so on) and any serializable type, including your own custom classes if they include the Serializable attribute. As an example, consider the PersonData class shown here:

<Serializable()> ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.