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);

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • ¥开启¥ 【iAPP实现进入界面执行逐一显】 〖2017-08-25 15:22:14〗 《//首先开一个线程,因...
    小菜c阅读 6,510评论 0 17
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,881评论 18 139
  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 31,759评论 18 399
  • 环信官方Demo源码分析及SDK简单应用 环信官方Demo源码分析及SDK简单应用-ChatDemoUI3.0 环...
    imGeek阅读 1,604评论 0 3
  • 你怎么还没买房?付个首付20w也可以啊! 听到这样的话,我心里在想我带借能凑齐15w就不错了。 那你老公在干什么?...
    霭霞阅读 219评论 0 0