Am using Cefsharp 39.0.0 to load a webpage inside a winform. Now while the page loads the form is blank. How do I show a loading gif?
public Browser() {
InitializeComponent();
string clientURL = "www.imdb.com";
ChromiumWebBrowser browser = new ChromiumWebBrowser(clientURL);
browser.Dock = DockStyle.Fill;
toolStripContainer.ContentPanel.Controls.Add(browser);
browser.RegisterJsObject("camera", new Camera());
}
I looked into NavStateChanged event. but am not sure how to go about using it to display a loading image from local resoruce in the form until the webpage loads fully.
EventHandler < NavStateChangedEventArgs > handler = null;
handler = (sender, args) = > {
//TODO : show a loading gif until the page load completes
//Wait for while page to finish loading not just the first frame
if (!args.IsLoading) {
browser.NavStateChanged -= handler;
MessageBox.Show("The page has completed loading", "Load completed", MessageBoxButtons.OK);
//TODO : once load complete show the actual page
}
};
answer from Alex Maitland on Cefsharp google groups
You can either load your own 'Loading Page' initially from local disk which is pretty fast.
First approach is using a
ResourceHandler
(You can load a stream from disk). https://github.com/cefsharp/CefSharp/blob/master/CefSharp.Example/CefExample.cs#L98 (You should also use aSchemeHandler
, which gives a bit more flexibility see https://github.com/cefsharp/CefSharp/blob/master/CefSharp.Example/CefSharpSchemeHandler.cs#L46)The option totally unrelated to
CefSharp
is to overlay an image over the control and remove it when your done. This is likely to give the best user experience. I'm sure somewhere like stackoverflow has information on this in a general sense. Remember if you hide the browser instance it will stop rendering (performance reasons), it will continue loading.If you don't need proxy support then disabling it should slightly speed up the initial load (proxy resolution takes a while relatively speaking) https://github.com/cefsharp/CefSharp/blob/master/CefSharp.Example/CefExample.cs#L39