O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

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

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()> ...

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