We help IT Professionals succeed at work.

open new form with webbrowser window

chetweewax asked
I have created my own web browser in vb6 for an intranet project but it was opening links with the _black in internet explorer, so i added the code below to get it to open in a new custom browser window...

Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
   Dim frmWB As Browser
   Set frmWB = New Browser

   frmWB.WebBrowser1.RegisterAsBrowser = True

   Set ppDisp = frmWB.WebBrowser1.Object
   frmWB.Visible = True
End Sub

The problem: the new window that is opening, the form will resize but the webbroser inside will not like on the parent window.  I am using the code below to resize webbrowser1 to the size i want in the form.

Private Sub form_resize()
   laststate = Browser.WindowState
   If Browser.WindowState <> vbMinimized Then
       WebBrowser1.Height = Browser.Height - 1300
   End If

   WebBrowser1.Width = Browser.Width - 300
End Sub
Watch Question

This works fine with me:

Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
    Dim frm As Browser
    Set frm = New Browser
    frm.WebBrowser1.RegisterAsBrowser = True
    Set ppDisp = frm.WebBrowser1.Object
    frm.Visible = True
End Sub

Private Sub Form_Resize()
    WebBrowser1.Width = Me.ScaleWidth - WebBrowser1.Left * 2
    WebBrowser1.Height = Me.ScaleHeight - WebBrowser1.Top * 2
End Sub

Note: Make sure that you don't have an initial/default page displayed when the form is loaded.



This is working great the only problem i am running into now is that when i close the open windows and open task manager my browser is still appearing open

It's not with the code. Please check your application if you loaded a window and now show it. Or probably a hidden or a windows with visible set to false.