找回密码
 立即注册

QQ登录

只需一步,快速开始

michaelcai4703

注册会员

12

主题

29

帖子

95

积分

注册会员

积分
95

活字格认证微信认证勋章

michaelcai4703
注册会员   /  发表于:2015-9-29 15:07  /   查看:3588  /  回复:2
系统粘贴板上有数据,如果我在窗体上放一个按钮来模拟ctrl+v功能,怎么触发呢?求解

2 个回复

倒序浏览
gw0506
超级版主   /  发表于:2015-9-29 15:57:00
沙发
调用ClipBoard类下的方法,详情参见:https://msdn.microsoft.com/zh-cn/library/system.windows.forms.clipboard.aspx
例如
  1. private void button1_Click(object sender, System.EventArgs e) {
  2.     // Takes the selected text from a text box and puts it on the clipboard.
  3.     if(textBox1.SelectedText != "")
  4.        Clipboard.SetDataObject(textBox1.SelectedText);
  5.     else
  6.        textBox2.Text = "No text selected in textBox1";
  7. }

  8. private void button2_Click(object sender, System.EventArgs e) {
  9.     // Declares an IDataObject to hold the data returned from the clipboard.
  10.     // Retrieves the data from the clipboard.
  11.     IDataObject iData = Clipboard.GetDataObject();

  12.     // Determines whether the data is in a format you can use.
  13.     if(iData.GetDataPresent(DataFormats.Text)) {
  14.        // Yes it is, so display it in a text box.
  15.        textBox2.Text = (String)iData.GetData(DataFormats.Text);
  16.     }
  17.     else {
  18.        // No it is not.
  19.        textBox2.Text = "Could not retrieve data off the clipboard.";
  20.     }
  21. }
复制代码
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2015-10-8 13:51:00
板凳
回复 1楼michaelcai4703的帖子

请问2楼版主提供的方案是否解决了你的问题?
为了给你提供更优质的服务,请对本次服务进行评分。我们会认真对待你提出的宝贵意见,谢谢        
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部