打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
C#复制、粘贴文本信息到剪贴板

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

复制:
private void button1_Click(object sender, System.EventArgs e) {
  // Takes the selected text from a text box and puts it on the clipboard.
  if(textBox1.SelectedText != ”")
  Clipboard.SetDataObject(textBox1.SelectedText);
  }

粘贴:
private void button2_Click(object sender, System.EventArgs e) {
  // Declares an IDataObject to hold the data returned from the clipboard.
  // Retrieves the data from the clipboard.
  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); 
  }
}
主要通过调用Clipborad的API完成。

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
C# 拖放功能的使用
C# 二维码生成和解析
c#与图像处理学习笔记(一)
C#中的Clipboard与ContextMenuStrip应用举例
VB.Net剪贴板实例(2)
是系统菜单--编辑项中的复制,粘贴
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服