Solved

How to prevent webbrowser ctrl from maintaining focus after navigate?

Posted on 2002-04-10
4
355 Views
Last Modified: 2008-03-03
Hi:

I have a simple project consisting of a textbox, a command button, a webbrowser and a single form on which those three controls are placed.  What happens is the user enters a web address in the textbox and then clicks the command button to navigate.  What I want to happen is for the textbox to regain the focus after the webbrowser finishes navigating.

The code behind the command button looks like this:

-- Begin --

'Perform search
webBrowser.Navigate txtSearchStr 'txtSearchStr = textbox
DoEvents

'Set focus back to the textbox
txtSearchStr.SetFocus

-- End --

This seems to work but if and only if the web page to which the webbrowser navigated does not have a textbox of it's own.  If it does, then the webpage tends to take focus.

I've also tried setting the textbox back to focus in the webbrowser's DocumentComplete and DownloadComplete events but the textbox still doesn't regain the focus.

I would like to allow the webbrowser to have a tabstop if possible.

Looking forward to your replies.

Thanks!

0
Comment
Question by:ksm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 20

Accepted Solution

by:
hes earned 100 total points
ID: 6931188
Try this
Private Sub WebBrowser_DocumentComplete(ByVal pDisp As Object, URL As Variant)
 If (pDisp is webBrowser.object) Then
   txtSearchStr.SetFocus
 End If
End Sub
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6931197
I tried this:

Private Sub txtSearchStr_LostFocus()
  If ActiveControl Is webBrowser Then
    txtSearchStr.SetFocus
  End If
End Sub

CHeers
0
 

Author Comment

by:ksm
ID: 6931499
Interestingly, my original code seems to work today.  However, I think your fine enhancement will help keep the app solid.  So I thank you.
0
 

Author Comment

by:ksm
ID: 6931513
angellll:

I can't use your code.  The reason is because I wanted to still be able to tab to or click on the webbrowser.  With your code, if I click on the webbrowser, the focus jumps back to the textbox.

Thanks, though.
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question