I can manually do a Control-A to select all the text on a WebBrowser control, and a Control-C to copy it to the clipboard.
But...
How can I get my VB.NET program to send AUTOMATICALLY a command (such as Control-A or Control-C) to the WebBrowser control?
I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
Private Sub WB_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WB.DocumentCompleted
Clipboard.Clear()
WB.Focus()
SendKeys.SendWait("^a") ' select
SendKeys.SendWait("^c") ' copy
txtData.Focus()
SendKeys.Send("^v") ' paste
End Sub
However, the DocumentCompleted sub appears to be getting executed more than once - the data appears repeated in txtData 2 or 3 times.
Perhaps I need to set a switch to stop it after one time?
The DocumentComplete event fires for every document that gets loaded into the WebBrowser control. So if the URL you are navigating to has frames, etc., you will get a DocumentComplete event fired for each one. To determine when all documents have finished loading completely, use the ReadyState property of the WebBrowser control:
If WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
Clipboard.Clear()
WB.Focus()
SendKeys.SendWait("^a") ' select
SendKeys.SendWait("^c") ' copy
txtData.Focus()
SendKeys.Send("^v") ' paste
End If
I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.