首页 > 代码库 > C#WinForm中复制、粘贴文本到剪贴板

C#WinForm中复制、粘贴文本到剪贴板

//复制:
private void button1_Click(object sender, System.EventArgs e) {
 
  if(textBox1.SelectedText != "")
     Clipboard.SetDataObject(textBox1.SelectedText);
}
 
//粘贴:
private void button2_Click(object sender, System.EventArgs e) {
  IDataObject iData = http://www.mamicode.com/Clipboard.GetDataObject();
  if(iData.GetDataPresent(DataFormats.Text)) {
     textBox2.Text = (String)iData.GetData(DataFormats.Text);
  }
}

C#WinForm中复制、粘贴文本到剪贴板