web browser control in winform with google chrome c#

16,346

Solution 1

VS default browser control use IE. You should use cefsharp for chrome browser. First include the library and initialize like this...

public ChromiumWebBrowser browser;
private void InitBrowser()
    {
        try
        {
            if (!Cef.IsInitialized)
            {
                CefSettings settings = new CefSettings();
                settings.BrowserSubprocessPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "CefSharp.BrowserSubprocess.exe");

                Cef.Initialize(settings);
            }
            string url = "www.google.com";

            browser = new ChromiumWebBrowser(url);             
            this.Controls.Add(browser);
            browser.Dock = DockStyle.Fill;

            browser.IsBrowserInitializedChanged += browser_IsBrowserInitializedChanged;
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message.ToString());
        }
    }

    private void browser_IsBrowserInitializedChanged(object sender, IsBrowserInitializedChangedEventArgs e)
    {
        if (((ChromiumWebBrowser)sender).IsBrowserInitialized)
        {
            //if needed then use dev tool
            browser.ShowDevTools();
        }
    }

For more info please see below link... https://github.com/cefsharp/CefSharp https://github.com/cefsharp/CefSharp/wiki/Quick-Start

Solution 2

The Browser component uses the Internet Explorer as engine, so if you want another browser you have to find a component for that.

CefSharp uses chromium as engine.

Share:
16,346

Related videos on Youtube

Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin over 1 year

    hello all i am creating a winform app in which i am showing a map to all the user but the problem is web browser control is taking ie7 as a default browser and map is not supporting in that particular browser,

    error:

    You are using a browser that is not supported by the Google Maps JavaScript API. Consider changing your browser.Learn moreDismiss

    i want to open the map from web browser control but not with ie, i want to show with google chrome to get rid of that error,

    and i have many administrative rights in my system i can't use registry

    is there any ways to do that?

  • gumuruh
    gumuruh over 2 years
    and how to control that cefsharp with automation task anyway?