1

private void button1_Click(object sender, System.EventArgs e)
{2
// Takes the selected text from a text box and puts it on the clipboard.3
if(textBox1.SelectedText != ”")4
System.Windows.Forms.Clipboard.SetDataObject(textBox1.SelectedText);5
}6

7
粘贴:8

private void button2_Click(object sender, System.EventArgs e)
{9
// Declares an IDataObject to hold the data returned from the clipboard.10
// Retrieves the data from the clipboard.11
IDataObject iData = System.Windows.Forms.Clipboard.GetDataObject();12
13
// Determines whether the data is in a format you can use.14

if(iData.GetDataPresent(DataFormats.Text))
{15
// Yes it is, so display it in a text box.16
textBox2.Text = (String)iData.GetData(DataFormats.Text); 17
}18
}19

20
