0

I have a TreeView with a list of URL's in it, and beside this TreeView, I have a WebBrowser1.

I'm trying to get it so that, when I click a link in the TreeView, focus is passed over to the WebBrowser so that with out any additional mouse clicks, I can start to scroll the newly loaded webpage.

I cannot seem to get this to work, no matter where in the code I add WebBrowser1.Focus()

I've tried adding this code in the following locations:

  • WebBrowser1_DocumentCompleted
  • WebBrowser1_Navigating
  • TreeView_MouseUp
  • TreeView_Click
  • TreeView_AfterSelect

None of these seem to hand over focus to the WebBrowser the way I had intended, I still have to click in the WebBrowser to gain access to the scroll

level42
  • 946
  • 2
  • 13
  • 33
  • 1
    http://stackoverflow.com/questions/5312755/focusing-webbrowser-control-in-a-c-sharp-application – Der Kommissar Apr 29 '15 at 20:07
  • Can you help me translate that? I can't read C# – level42 Apr 29 '15 at 20:14
  • This line is what you need: `webBrowser1.Document.Body.Focus()` – Der Kommissar Apr 29 '15 at 20:15
  • `webBrowser1.Document.Focus()` seems to work fine as well. – Joe Uhren Apr 29 '15 at 20:15
  • Hmm, so it only seems to work if the mouse is hovering over the webbrowser – level42 Apr 29 '15 at 20:17
  • Yes, just like a normal web browser. What exactly are you trying to do? You could always programmatically position the mouse cursor over the web browser control using something like `System.Windows.Forms.Cursor.Position = New Point(Me.Location.X + Me.WebBrowser1.Location.X + 50, Me.Location.Y + Me.WebBrowser1.Location.Y + 50)` – Joe Uhren Apr 29 '15 at 20:53
  • Hmm, I guess I just never noticed as my personal webbrowser is always full screen, and this control one is a smaller size. – level42 Apr 29 '15 at 21:01

0 Answers0