?
Solved

No form Key events w/ WebBrowser control

Posted on 1998-02-24
3
Medium Priority
?
379 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
[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
  • 3
3 Comments
 
LVL 6

Accepted Solution

by:
anthonyc earned 400 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

801 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