Solved

No form Key events w/ WebBrowser control

Posted on 1998-02-24
3
370 Views
Last Modified: 2012-06-27
How do I get a VB5 form's KeyUp event to fire when none of
its controls are enabled or have focus?  I've got the KeyPreview property set to True, but the KeyUp event does not fire.

My form has one control on it: a WebBrowser control.  Unless I explicitly click the control first, the form's KeyUp will never fire.

To see this behavior, create a new application.  On the main form, drop a WebBrowser control.  Then add the following code:

Private Sub Form_Load()
    WebBrowser1.Navigate "d:\somepage.htm"
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    Beep
End Sub

0
Comment
Question by:Keysoft
  • 3
3 Comments
 
LVL 6

Accepted Solution

by:
anthonyc earned 100 total points
Comment Utility
Seems like a bug in MS to me.  Try this:

private sub form_activate()
  static boolLoad as boolean

  if not boolLoad then
     webbrowser1.setfocus
     boolLoad = true
  end if
end sub
0
 
LVL 6

Expert Comment

by:anthonyc
Comment Utility
reject this answer, it doesn't work
0
 
LVL 6

Expert Comment

by:anthonyc
Comment Utility
Here is a work around (not a pretty one)

1)  Add a picture box to the form
2)  Make the picture box borderstyle flat
3)  Place the webbrowser control inside the picture box
4)  Add this code to the form_load

    WebBrowser1.Move 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight

5)  Add this form_activate

Private Sub form_activate()
  Static boolLoad As Boolean

  If Not boolLoad Then
     Picture1.SetFocus
     DoEvents
     boolLoad = True
  End If
End Sub




0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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 trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

763 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