Webbrowser steals focus

前端 未结 7 1888
天命终不由人
天命终不由人 2021-01-06 07:17

I\'m using webbrowser control in my winforms app (c#). And when it is doing automation things, I\'m losing focus control from the window I was working with. Webbrowsers\' fo

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-06 07:50

    My solution for sending the focus back to a form:

            Private Sub Web_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles Web.DocumentCompleted
        If Me.Visible = False Then
            For Each f As Form In My.Application.OpenForms
                If TypeOf f Is frmLogin Then
                    Dim fl As frmLogin = DirectCast(f, frmLogin)
                    If fl.Visible = True Then
                        fl.Focus()
                        Exit For
                    End If
                End If
            Next
        End If
    End Sub
    

提交回复
热议问题