The clipboard is an area of memory in Windows that is set aside to allow users and applications to move text, images, and other data between forms. It can best be explained by saying that it is where data goes when a user chooses to copy and paste. Besides the normal Ctrl-C/V and edit menu options that allow users to add and retrieve things from the clipboard, it can also be accessed programmatically in Visual Basic using a few simple commands.
- Skill level:
- Moderately Easy
Other People Are Reading
Things you need
- Visual Basic 2008
Create a new Visual Basic project. The easiest way to do this is to click on the File menu and select create new project. Press OK or next for any dialogue boxes that pop up until you find yourself at the "Graphical User Interface (GUI)" designer with a blank window for your application.
Drag a label from the components list on the left hand side of the screen into your window. Place it somewhere near the top of your window. Look for the property list editor on the bottom right hand side of the screen and change the "text" property so that it reads, "This is the text that will be copies to the clipboard."
Drag a button from the components list and place it next to or just below the label you added in Step 2. Go to the properties editor and change the "text" property so that it reads "Copy." Then go to the "name" property and change it to "CopyButton."
Drag another button from the components list and place it below the last button. Change its "text" property to "Paste" and its "name" property to "PasteButton."
Drag a RichTextBox from the components list and place it on the form. Don't make any modifications to its properties.
Double click the "Copy" button. This will take you out of the GUI designer and into the source code editor. It will also create an event function for your button. This function will be called whenever anyone clicks the button in your application.
Paste the following code into the event function:
This will move the text from the label into the clipboard using the standard ANSI text format. Alternative data formats you can use include Rich Text Format(RTF), Unicode, Hyper Text Markup Language (HTML) and Comma Separated Value (CSV).
Click the "design" tab to go back to the GUI Designer. Double click the "Paste" button to go back to the source editor and automatically create an event function.
Write the following code:
RichTextBox1.Text = My.Computer.Clipboard.GetText(System.Windows.Forms.TextDataFormat.Text)
Tips and warnings
- This tutorial was written for Visual Basic 2008. The same operations may vary slightly for older versions.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for