首先画一个这样的对话框:

截图00

第一行的文本框名称为TextBox1,第二行文本框名称为TextBox2

Button1将TextBox1中的内容复制到剪切板。

Button2将剪切板的内容粘贴到TextBox2。

示例代码如下:

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If TextBox1.Text <> "" Then
            Clipboard.SetText(TextBox1.Text)
        Else
            MessageBox.Show("There isn't text in textBox1")
        End If

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        If Clipboard.ContainsText() Then
            TextBox2.Text = Clipboard.GetText()
        Else
            MessageBox.Show("Could not retrieve data off the clipboard.")
        End If

    End Sub
End Class

GetText etrieves text data from the Clipboard in the Text or UnicodeText format, depending on the operating system.

This method returns text data in the UnicodeText format on Windows XP Home Edition, Windows XP Professional, Windows Server 2003 and Windows 2000. Otherwise, this method returns text data in the Text format.

Use the ContainsText method to determine whether the Clipboard contains text data before retrieving it with this method.

Use the SetText method to add text data to the Clipboard.

The Clipboard class can only be used in threads set to single thread apartment (STA) mode. To use this class, ensure that your Main method is marked with the STAThreadAttribute attribute.

SetText, ContainsText,GetText都可以包含一个TextDataFormat枚举参数。