I have a WebBrowser control in a form with textual data and in that form I am introducing 2 buttons. One to copy the entire contents(CTRL+A, CTRL+C) and the other to copy only the selected (using a mouse) text i.e. only a CTRL+C and then paste it to a notepad.
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. This will enable the Context menu in the control from which you can Copy/Paste.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With