Imports DotNetBrowser
Imports DotNetBrowser.Events
Imports DotNetBrowser.WinForms

Public Class Form1
    Private browserView As WinFormsBrowserView

    Public Sub New()

        InitializeComponent()

        browserView = New WinFormsBrowserView()
        Controls.Add(browserView)

        AddHandler browserView.Browser.FinishLoadingFrameEvent, Sub(sender, e)
                                                                    If e.IsMainFrame Then
                                                                        OnPageLoaded(e)
                                                                    End If
                                                                End Sub
        browserView.Browser.LoadURL("http://google.com")
    End Sub

    Private Sub OnPageLoaded(e As FinishLoadingEventArgs)
        BeginInvoke(Sub() CallbackJsButton.Enabled = True)
        Dim window As JSValue = e.Browser.ExecuteJavaScriptAndReturnValue("window")
        window.AsObject().SetProperty("Account", New Account(Me))
    End Sub

    Private Sub CallbackJsButton_Click(sender As Object, e As EventArgs) Handles CallbackJsButton.Click
        browserView.Browser.ExecuteJavaScript("window.Account.Save('FirstName', 'LastName');")
    End Sub
End Class

Public Class Account
    Private form1 As Form1

    Public Sub New(form1 As Form1)
        Me.form1 = form1
    End Sub

    Public Sub Save(firstName As String, lastName As String)
        form1.BeginInvoke(Sub() MessageBox.Show(form1, "firstName = " + firstName + ", lastName = " + lastName, "Message"))
    End Sub

End Class