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 = Clipboard.GetDataObject();

  if(iData.GetDataPresent(DataFormats.Text)) {

     textBox2.Text = (String)iData.GetData(DataFormats.Text);

  }

}

  

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

发布了17 篇原创文章 · 获赞 224 · 访问量 29万+

猜你喜欢

转载自blog.csdn.net/cxu123321/article/details/105066986