private void button1_Click(object sender, EventArgs e)
{
string str = textBox1.Text;
//Clipboard.SetDataObject(str);//将数据粘贴到剪贴板
Clipboard.SetData(DataFormats.Text ,str);//以指定的格式,将数据粘贴到剪贴板
}
private void button2_Click(object sender, EventArgs e)
{
IDataObject iData = Clipboard.GetDataObject();
// Determines whether the data is in a format you can use.
if (iData.GetDataPresent(DataFormats.Text))
{
// Yes it is, so display it in a text box.
textBox2.Text = (String)iData.GetData(DataFormats.Text);
}
else
{
// No it is not.
textBox2.Text = "Could not retrieve data off the clipboard.";
}
}
c#剪切和粘贴
最新推荐文章于 2024-06-05 10:19:58 发布