通过c#代码复制粘贴内容 [英] copy paste content by c# code

查看:80
本文介绍了通过c#代码复制粘贴内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在winform中有webbrowser控件。在该控件中加载了一个html页面。如果我通过选择所有(ctrl + a然后ctrl + c)复制该页面并粘贴到word文件,该文件结构良好,所有该页面的图像和样式。



现在看代码....................



webBrowser1.Document.ExecCommand(SelectAll,true,null);

webBrowser1.Document.ExecCommand(Copy,true,null );



这些代码选择并将控件的内容复制到剪贴板。如果我打开一个word文档并通过ctrl + v粘贴它工作正常。



现在,复制选项是通过代码完成的(上面的代码),所以我想通过c#代码粘贴(ctrl + v)选项。

解决方案

请参阅类 System.Windows.Forms.Clipboard

http://msdn.microsoft.com/en-us/librar y / system.windows.forms.clipboard%28v = vs.110%29.aspx [ ^ ]。



但是它看起来你正试图通过剪贴板移动软件中的数据。这是一种滥用。您不应该触摸剪贴板(除非这是命令的目的),因为用户可能依赖于其内容,例如,使用其他一些应用程序。



< DD> -SA

I have webbrowser control in winform.In that control a html page is loaded.If I copy that page by selecting all(ctrl+a then ctrl+c) and paste to a word file,the file is structured fine with all the images and styles of that page.

Now see the codes....................

webBrowser1.Document.ExecCommand("SelectAll", true, null);
webBrowser1.Document.ExecCommand("Copy", true, null);

These codes are selecting and copying the content of the control to clipboard.If I then open a word document and paste it by ctrl+v that is working fine.

Now, copy option is done by code (above code),so I want the paste(ctrl+v) option by c# code.

解决方案

Please see the class System.Windows.Forms.Clipboard:
http://msdn.microsoft.com/en-us/library/system.windows.forms.clipboard%28v=vs.110%29.aspx[^].

But it looks like you are trying to move data in your software through the clipboard. This is a kind of abuse. You should not touch the clipboard (unless this is the purpose of the command), because the user may depend on its content, say, using some other applications.

—SA


这篇关于通过c#代码复制粘贴内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆