Clipboard Sample

To get samples and instructions for installing them, see the following:

  • Click Samples on the Visual Studio Help menu.

    For more information, see Locating Sample Files.

  • The most recent versions and the complete list of samples are available on the Visual Studio 2008 Samples Web site.

  • You can also locate samples on your computer's hard disk. By default, samples and a Readme file are copied to a folder under \Program Files\Visual Studio 9\Samples\. For Visual Studio Express Editions, all samples are located on the Internet.

To view the sample documentation

  1. In Solution Explorer, double-click the Documentation folder.

  2. If you are using Visual Basic Express Edition, right-click ReadMe.htm in the Documentation folder. Click View in Browser.

  3. If you are using another version of Visual Basic, double-click ReadMe.htm in the Documentation folder.

Demonstrates

The main form's menu commands control the two primary tasks in using the Clipboard—copying to it and retrieving from it. Six data types are copied and pasted by using the My.Computer.Clipboard Object:

  • Image   This feature uses the My.Computer.Clipboard.SetImage Method and the My.Computer.Clipboard.GetImage Method to copy the picture from one PictureBox control to another. The image file is stored in My.Resources.

  • Text   This feature uses the My.Computer.Clipboard.SetText Method and the My.Computer.Clipboard.GetText Method to copy text from one TextBox control to another. The My.Computer.Clipboard.SetText Method is overloaded. The overload used in this task has no parameters and it copies any kind of text found in the Clipboard.

  • Rich text   Like the "text" feature, this one uses the My.Computer.Clipboard.SetText Method and the My.Computer.Clipboard.GetText Method to copy and paste text. This feature uses the overload of the My.Computer.Clipboard.SetText Method that takes a TextDataFormat enumeration. The value passed is Rtf. Therefore, only rich text is copied.

  • HTML   Similar to the "rich-text" feature, this one uses a value (Html) of the TextDataFormat enumeration to retrieve just HTML from the Clipboard.

  • Class instance   The Pixel class is defined in the project and has the Serializable attribute. The My.Computer.Clipboard.SetData Method and the My.Computer.Clipboard.GetData Method can be used to copy and paste the data. The LoadPixel method creates a text string to write to the form.

  • File   A file is copied to the Clipboard by copying from Windows Explorer. The file name is retrieved by using My.Computer.Clipboard.GetFileDropList Method.

In each case, the data is copied from the source control in the left column and pasted into the destination control in the right column.