How to change url using CefSharp WinForms

So I decided to submit CefSharp again, grabbed Nedet CefSharp.Winforms and crashed in the following code:

    public CefSharp.WinForms.ChromiumWebBrowser browser;

    public Form1() {
        InitializeComponent();

        browser=new CefSharp.WinForms.ChromiumWebBrowser( "http://www.imdb.com" ) {
            Dock=DockStyle.Fill,
        };
        tabPage2.Controls.Add( browser );
    }

      

... which is working. It creates a web browser control and loads the page (YAY !!). Now what I want to do is based on the selection of users in the ListView, I want to change the page from http://www.imdb.com

to something else. Essentially looking for a way to do the same as WebBrowser.Navigate( ... )

from the IE browser component, but in CefSharp.WinForms.

It seems pretty silly (and pointless) if there is no way to change the url after the browser is initialized, so it makes sense that there should be a way.

browser.Address

is as close to the component itself as possible, but it's a readonly property.

Thanks in advance for your help with this issue.

+3


source to share


1 answer


As pointed out by Majed DH in the comments, the correct solution to this exact and very clear question is:

The WPF version has ChromiumWebBrowser.Load (string url). i think it might be in winform version too. - Majed DH May 24 at 10:29 am

More specifically, a sample code on how to do this looks like this:



public CefSharp.WinForms.ChromiumWebBrowser browser;

public Form1() {
    InitializeComponent();

    browser=new CefSharp.WinForms.ChromiumWebBrowser( "http://www.imdb.com" ) {
        Dock=DockStyle.Fill,
    };
    this.Controls.Add( browser );

    // Simply pass the URL you wish to navigate to, to the 'Load' method
    browser.Load( "http://www.google.ca" );
}

      

In CefSharp, a functionally equivalent method for Navigate

WebBrowser-based native control is Load

.

Footnote: On further investigation, there is no clear indication of why the developers of the CefSharp project chose to use Load

when it Navigate

more accurately describes the action and is also more consistent with the built-in WebBrowser control method.

+9


source







All Articles