一个剪切板示例

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

截图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枚举参数。

转载于:https://www.cnblogs.com/cuishengli/archive/2013/05/01/3052768.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值