?
Solved

webbrowser causing cursor to disappear

Posted on 2011-04-18
18
Medium Priority
?
447 Views
Last Modified: 2012-05-11
On a form, I have a textbox, and a webbrowser control, which has google loaded up.

I click in my textbox and I have a nice flashing cursor.

I click in a black space in the webbrowser, then click in my textbox, and there is no blinking cursor, but I can type into that textbox.

Any ideas?  I've been working on this bug forever now.
0
Comment
Question by:hrolsons
  • 11
  • 7
18 Comments
 
LVL 17

Expert Comment

by:Carlos Villegas
ID: 35420623
Hello, try add this to your form:
    Private Sub Form1_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.MouseEnter
        Cursor = Cursors.Default
    End Sub

Open in new window

0
 
LVL 17

Expert Comment

by:Carlos Villegas
ID: 35420631
Oh, is this VB classic?
0
 

Author Comment

by:hrolsons
ID: 35420637
Yes, VB6
0
Industry Leaders: 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!

 
LVL 17

Expert Comment

by:Carlos Villegas
ID: 35420649
Ok, can you try this instead?
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Screen.MousePointer = MousePointerConstants.vbDefault
End Sub

Open in new window

0
 

Author Comment

by:hrolsons
ID: 35420722
Didn't work, yv989c
0
 
LVL 17

Expert Comment

by:Carlos Villegas
ID: 35420733
I'm working on it, I know what the problem is ;) I will let you know when I got something.
0
 
LVL 17

Expert Comment

by:Carlos Villegas
ID: 35420844
Hello buddy!
In a form add a webbrowser control named WebBrowser1, and some textboxes to play, use this code on it:
Private Sub Form_Load()
    WebBrowser1.Navigate2 "www.google.com"
End Sub

Private Sub WebBrowser1_LostFocus()
    Dim ac As Control
    Set ac = Me.ActiveControl
    Me.SetFocus
    If Not ac Is Nothing Then
        If ac.Enabled And ac.Visible Then
            ac.SetFocus
        End If
    End If
End Sub

Open in new window

I hope this work for you.
0
 

Author Comment

by:hrolsons
ID: 35420867
Looks like it's close.  Still having a problem when WebBrowser1 loses focus to WebBrowser2.
0
 
LVL 17

Expert Comment

by:Carlos Villegas
ID: 35420871
Easy bro, add:
Private Sub WebBrowser2_LostFocus()
    Dim ac As Control
    Set ac = Me.ActiveControl
    Me.SetFocus
    If Not ac Is Nothing Then
        If ac.Enabled And ac.Visible Then
            ac.SetFocus
        End If
    End If
End Sub

Open in new window

0
 

Author Comment

by:hrolsons
ID: 35420888
No, click on webbrowser1 and then click on webbrowser2 and an error will happen.

"Object doesn't support this property or method"
0
 
LVL 17

Expert Comment

by:Carlos Villegas
ID: 35420894
what code line?
0
 
LVL 17

Accepted Solution

by:
Carlos Villegas earned 2000 total points
ID: 35421046
What if:
Private Sub WebBrowser2_LostFocus()
    On Error Resume Next
    Dim ac As Control
    Set ac = Me.ActiveControl
    Me.SetFocus
    If Not ac Is Nothing Then
        If ac.Enabled And ac.Visible Then
            ac.SetFocus
        End If
    End If
End Sub

Open in new window

0
 

Author Comment

by:hrolsons
ID: 35421385
I see your "On Error Resume Next"

Would I need "On Error goto 0" at the end of the sub, or does it default back to that for the rest of my code after the sub ends?
0
 
LVL 17

Expert Comment

by:Carlos Villegas
ID: 35421417
I don't remember very well, I don't think so, but to be sure, add a command button and raise an error, like this: Err.Raise
If the error is throw then its fine.
0
 
LVL 17

Expert Comment

by:Carlos Villegas
ID: 35421425
I don't think that you need the On Error goto 0 at the end
0
 

Author Comment

by:hrolsons
ID: 35421437
It didn't show the error.
0
 

Author Comment

by:hrolsons
ID: 35421458
If I press the button twice it does come up.  It's almost like the first click you make after a webbrowser, doesn't work.  You fixed my first problem though, so I'll move on.  Thank You.
0
 
LVL 17

Expert Comment

by:Carlos Villegas
ID: 35421490
Thanks buddy, but now I see that it is more simple:
Private Sub WebBrowser1_LostFocus()
    On Error Resume Next
    Me.SetFocus
End Sub

Open in new window

Just make use of this code, it still a little buggy, but this fix your cursor problem.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
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.
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…
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 Month14 days, 9 hours left to enroll

839 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