简体   繁体   English

在Win窗体中模拟WebBrowser控件上的复制粘贴

[英]Simulating a Copy Paste on a WebBrowser Control in Win Forms

I have a WebBrowser control in a form with textual data and in that form I am introducing 2 buttons. 我有一个带有文本数据的表单中的WebBrowser控件,在该表单中我引入了2个按钮。 One to copy the entire contents(CTRL+A, CTRL+C) and the other to copy only the selected (using a mouse) text ie only a CTRL+C and then paste it to a notepad. 一个用于复制整个内容(CTRL + A,CTRL + C),另一个用于复制选定的(使用鼠标)文本,即仅复制CTRL + C,然后将其粘贴到记事本中。

Code for Copy: (this works partially correct. copies only upto a certain point) 复制代码:(这部分工作正常。只复制到某一点)

this.WebBrowser.Document.Focus();
SendKeys.SendWait("^a");
SendKeys.SendWait("^a^c");
this.WebBrowser.Refresh();

Code for Copy Selected: (this does not work at all) 所选复制代码:(这根本不起作用)

this.WebBrowser.Document.Focus();
SendKeys.SendWait("^c");
this.WebBrowser.Refresh();

Can you please tell me if this is the right way? 如果这是正确的方法,你能告诉我吗?

Try this for Copy: 试试这个复制:

this.WebBrowser.Document.ExecCommand("Copy", False, vbNull)

Or Use the property WebBrowser.IsWebBrowserContextMenuEnabled = True. 或者使用属性WebBrowser.IsWebBrowserContextMenuEnabled = True。 This will enable the Context menu in the control from which you can Copy/Paste. 这将启用控件中的“上下文”菜单,您可以从中复制/粘贴。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM