Search code examples
vb.netbrowsertabshandlergeckofx

Event Handler Tabbed Web Browser With GeckoFX


I tried to make a tabbed web browser with geckofx. This is my code to make a new tab:

    Dim t As New TabPage
    Dim bro As New GeckoWebBrowser
    bro.Dock = DockStyle.Fill
    t.Text = "New Tab"
    t.Controls.Add(bro)
    TabMain.TabPages.Add(t)
    TabMain.SelectedTab = t
    bro.Navigate("http://www.google.com")

Now, how to handle DocumentCompleted and DocumentTitleChanged in GeckoWebBrowser? I want to show message if DocumentCompleted event triggered and change window title if DocumentTitleChanged event triggered.


Solution

  • Not sure about the vb.net syntax, but the principle is simple (and it should be fairly simple to transfer from c# to vb)

    So, for example: 1) attach an event handler to your browser

    browser.DocumentCompleted += browser_DocumentCompleted;

    2) generate the method that will do what you need:

    void browser_DocumentCompleted(object sender, Gecko.Events.GeckoDocumentCompletedEventArgs e)
            {
                GWB browser = (GWB)sender;
                if (browser.Document == null) return;
                //do anything you wanna do when document is completed
                AnyMethodBasedOnBrowser(browser);
    
                //e.g. access GUI elements by property binding 
                TabTitle = "Complete";
    
                //or even alternatively access the control directly
                var TabControl = browser.Parent;
                //etc etc
            }
    

    That should do the trick for you!