Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to prevent webbrowser ctrl from maintaining focus after navigate?

Posted on 2002-04-10
4
Medium Priority
?
357 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 400 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

722 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