15

So, I decided to give CefSharp another go, grabbed the CefSharp.Winforms nuget, and dropped 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 works. It creates the webbrowser control, and loads the page (YAY !!). Now, what I want to do, is based on a users selection in a ListView, I want to change the page from http://www.imdb.com to something else. Essentially looking for a way to do the same thing that WebBrowser.Navigate( ... ) from the IE Browser component, but in CefSharp.WinForms.

Seems rather silly (and pointless), if there is no way to change the URL after the browser is initialized, so on that, logically, there must be a way.

browser.Address is as close as I can find within the component itself, but it is a readonly property.

Thanks in advance for any assistance with this matter.

Kraang Prime
  • 9,981
  • 10
  • 58
  • 124
  • 4
    There is a `ChromiumWebBrowser.Load(string url)` in WPF version . i think it may be there in winform version too. – Majed DH May 24 '15 at 10:29

1 Answers1

28

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

There is a ChromiumWebBrowser.Load(string url) in WPF version . i think it may be there in winform version too. – Majed DH May 24 at 10:29

More specifically, a code example on how this is done, is as follows:

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, the functionally equivalent method to the native WebBrowser controls' Navigate method, is Load.

Footnote: Upon further research, there is no clear indication as to why the developers of the CefSharp project chose to use Load when Navigate more accurately describes the action and is also more consistent with the built-in WebBrowser control's method.

Kraang Prime
  • 9,981
  • 10
  • 58
  • 124
  • 2
    The usage of `Load` method wasn't worked for me when using `CefSharp.WinForms.ChromiumWebBrowser` inside a WPF `WindowsFormsHost`. – Eido95 Apr 04 '16 at 17:27
  • 5
    Not that I disagree, but still funny that you describe your own question as "precise and very clear" in your own answer – andersand Sep 29 '17 at 13:59
  • 1
    @andersand - understandable how it comes across without prior history - some comments were removed, and additionally there were some who were pushing lack of clarity as a reason to not provide a solution (or to silence the question). I'm sure you have noticed that CEF has inflated results as "just use it", but little to no functional documentation. I felt this was something the community needs (8000 views at the moment) which was why I left it. The "solutions" were very convoluted and/or broken, which as the code above shows - they don't need to be. – Kraang Prime Sep 30 '17 at 21:43
  • Hi , When i use `browser.Load(...)` it open this url in wayback any body tell me why ? I am new in it – Ahmad Dec 22 '19 at 17:33