您的位置:首页 > 编程语言 > C#

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

2013-01-20 23:56 302 查看
//复制:
privatevoidbutton1_Click(objectsender,System.EventArgse){
  //如果选中部分不为空把选中的内容复制到剪贴板
  if(textBox1.SelectedText!=”")
  Clipboard.SetDataObject(textBox1.SelectedText);
  }
//粘贴:
privatevoidbutton2_Click(objectsender,System.EventArgse){
  //DeclaresanIDataObjecttoholdthedatareturnedfromtheclipboard.
  //Retrievesthedatafromtheclipboard.
  IDataObjectiData=Clipboard.GetDataObject();
  //Determineswhetherthedataisinaformatyoucanuse.
  if(iData.GetDataPresent(DataFormats.Text)){
  //Yesitis,sodisplayitinatextbox.
  textBox2.Text=(String)iData.GetData(DataFormats.Text);
  }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: