Solved

No form Key events w/ WebBrowser control

Posted on 1998-02-24
3
375 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
ID: 1457805
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
ID: 1457806
reject this answer, it doesn't work
0
 
LVL 6

Expert Comment

by:anthonyc
ID: 1457807
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

828 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