frmBrowser Form
When creating a project with the VB Application Wizard, if you indicate that you want your users to be able to access the Internet from your application, the wizard adds the frmBrowser form to the application. Choosing Web Browser from the View menu then opens the form. The code generated in the mnuViewWebBrowser_Click event in frmMain looks like this:
Private Sub mnuViewWebBrowser_Click() Dim frmB As New frmBrowser frmB.StartingAddress = "http://www.microsoft.com" frmB.Show End Sub
This code upgrades to the following:
Public Sub mnuViewWebBrowser_Click(ByVal eventSender As _ System.Object, _ ByVal eventArgs As System.EventArgs) _ Handles mnuViewWeb Browser.Click Dim frmB As frmBrowser = New frmBrowser frmB.StartingAddress = "http://www.microsoft.com" frmB.Show() End Sub
If this is an MDI project, you need to adjust the behavior of the frmBrowser form. Open the code window for frmBrowser and search for the line Me.Show. This statement is in the Sub New method within the Windows Form Designer generated code hidden region. Remove the Me.Show line.
The reason for removing the line is to avoid an event ordering issue. This line causes the Form_Load event to fire before the mnuViewWebBrowser method has assigned the StartingAddress property of the form. After you remove the Me.Show line, the frmBrowser form will navigate to the default Web site when it is first opened.