Clipboard Sample
This sample shows you how to copy and retrieve Clipboard items in multiple formats.
To get samples and instructions for installing them
Do one or more of the following:
On the Help menu, click Samples.
The Readme displays information about samples.
Visit the Visual Studio 2008 Samples Web site. The most recent versions of samples are available there.
Locate samples on the computer on which Visual Studio is installed. By default, samples and a Readme file are installed in drive:\Program Files\Microsoft Visual Studio 9.0\Samples\lcid. For Express editions of Visual Studio, all samples are located online.
For more information, see Visual Studio Samples.
Security Note: |
---|
This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties. |
To view the sample documentation
In Solution Explorer, double-click the Documentation folder.
If you are using Visual Basic Express, right-click ReadMe.htm in the Documentation folder. Click View in Browser.
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.
See Also
Tasks
How to: Write to the Clipboard in Visual Basic
How to: Clear the Clipboard in Visual Basic
How to: Read from the Clipboard in Visual Basic
How to: Retrieve an Image from the Clipboard in Visual Basic