How to Copy to Clipboard in Visual Basic

Written by amber d. walker
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Copy to Clipboard in Visual Basic
In Windows, the clipboard is an area of memory used to hold information temporarily for users and programs. (blank paper on clipboard image by Nataliya Galkina from

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

Things you need

  • Visual Basic 2008

Show MoreHide


  1. 1

    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.

  2. 2

    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."

  3. 3

    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."

  4. 4

    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."

  5. 5

    Drag a RichTextBox from the components list and place it on the form. Don't make any modifications to its properties.

  6. 6

    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:

    My.Computer.Clipboard.SetText(Label1.Text, System.Windows.Forms.TextDataFormat.Text)

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

  7. 7

    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.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.