Solved

No form Key events w/ WebBrowser control

Posted on 1998-02-24
3
378 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 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…

724 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