Simulating copy insertion in a WebBrowser control in Win Forms

I have a WebBrowser control in a form with text data, and in this form I present two buttons. One to copy the entire contents (CTRL + A, CTRL + C), and the other to copy only the selected (using the mouse) text, that is, only CTRL + C, and then paste it into notepad.

Code for copying: (this works partially correctly, copies only to a certain point)

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

Code to copy: (this does not work at all)

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

Could you tell me if this is correct?

+4
source share
1 answer

Try this for copy:

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

Or Use the WebBrowser.IsWebBrowserContextMenuEnabled = True property. This will allow a context menu in the control from which you can copy / paste.

+8
source

All Articles