Solved

How to prevent webbrowser ctrl from maintaining focus after navigate?

Posted on 2002-04-10
4
351 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
  • 2
4 Comments
 
LVL 20

Accepted Solution

by:
hes earned 100 total points
Comment Utility
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 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
I tried this:

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

CHeers
0
 

Author Comment

by:ksm
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now