Solved

No form Key events w/ WebBrowser control

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
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…
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…

863 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

25 Experts available now in Live!

Get 1:1 Help Now