[SOLVED] Get webpage title with CEFSharp in TWBP

I'm trying to get the title of the website but it keeps giving me an error saying

System.NullReferenceException: 'Object reference not set to an instance of an object.'

ColinVerhey.TWBP.TabBar.getSelectedTab(...) returned Nothing.

Like 0 Dislike

This is my method

     Form1.TwbpTabs1.TabContainer.getSelectedTab.TabTitle = e.Title.ToString

Like 0 Dislike

Hiya [notify]ShoutOut! Technology[/notify],
You can only call "e.Title" in the web-browser control's "OnBrowserTitleChanged" event, usually you need to invoke it; like this:

'In your OnBrowserTitleChanged event:
Form1.BeginInvoke(Sub() Form1.TwbpTabs1.TabContainer.getSelectedTab.TabTitle = e.Title)

Hope this helps! 1f609

Like 0 Dislike

I tried your method but it keeps giving me this error

 System.InvalidOperationException: 'Invoke or BeginInvoke cannot be called on a control until the window handle has been created.'

After some research, I found this.

 If (Form1.IsHandleCreated) Then
            Form1.CreateControl();
        Form1.BeginInvoke(Sub() Form1.TwbpTabs1.TabContainer.getSelectedTab.TabTitle = e.Title)

        End If

This time, it didn't give me any errors but it didn't display any title of some sort on the tabpage

admin wrote:

Hiya @ShoutOut! Technology,
You can only call "e.Title" in the web-browser control's "OnBrowserTitleChanged" event, usually you need to invoke it; like this:

'In your OnBrowserTitleChanged event:
Form1.BeginInvoke(Sub() Form1.TwbpTabs1.TabContainer.getSelectedTab.TabTitle = e.Title)

Hope this helps! 1f609

Like +1 Dislike

Nice! You could also try this (as used in the "MinimalExample", here: https://github.com/cefsharp/CefSharp.Mi … orm.cs#L49):

Form1.InvokeOnUiThreadIfRequired((Sub() Form1.TwbpTabs1.TabContainer.getSelectedTab.TabTitle = e.Title)

You'll have to import the following:

Imports CefSharp.WinForms.Internals

Like 0 Dislike

Here is some code straight from my Verdex Webbrowser that I used to get the Title in the tabs (I don't know the code to the twbp selected tabs title code so ill just use placeholder)
In form load:

web.TitleChanged += web_titlechanged

and in the sub:

Private Sub web_titlechanged(ByVal sender As Object, ByVal e As TitleChangedEventArgs)
    Me.Invoke(New MethodInvoker(Function()
        autocompeltepnl.Visible = False
        Try
            *placeholder* = e.Title
        Catch __unusedNullReferenceException1__ As NullReferenceException
            *placeholder* = "Untitled"
        End Try

    End Function))
End Sub

Also, import the following:

Imports CefSharp.Winforms
Imports CefSharp
A post by brwck

Like +1 Dislike