Windows Forms: Use the Clipboard

This sample shows you how to place and retrieve items from the Clipboard in multiple formats. It demonstrates the primary properties and methods used when using the Clipboard.

Featured Highlights:

The text "The Clipboard is Cool!" is provided in multiple formats (as class variables).

The text can be copied to the Clipboard in a single format, or stored in the Clipboard as multiple formats concurrently, all from the
"Edit" menu.

An image can also be loaded and stored in the Clipboard from the "Edit" menu.

The "Paste As" menu is dynamically generated from the various formats that are stored in the Clipboard.

Items can be copied to the clipboard from other windows applications, and pasted into the sample form. The opposite is also true.

Requirements:

Requires Microsoft Visual Studio.NET and Windows 2000 or Windows XP.

Running the Sample:

To use this sample, run the application and then explore the "Edit" menu options. Select "Edit -> Copy Text As -> RTF", as
an example. Then select "Edit -> Paste As -> Rich Text Format". You can then examine how the text is pasted differently into a
RichTextBox and a TextBox.

Then try the same with HTML. Note that the RichTextBox does not support the HTML format. Try to paste the HTML into an HTML editor
(a Visual Studio .NET HTML document works well). See how it is pasted correctly.

Then try "Edit -> Paste As -> All Formats", and notice that multiple versions of the same text are stored on the Clipboard. You can now paste
as Text, RTF, HTML, and a proprietary XML format.

See also

Clipboard Class  Placing data on the Clipboard  Retrieve Information from the Clipboard