使用 google chrome c# 在 winform 中进行网络浏览器控制

3 c# google-maps google-chrome winforms

大家好,我正在创建一个 winform 应用程序,在其中向所有用户显示地图,但问题是 Web 浏览器控件将 ie7 作为默认浏览器,而该特定浏览器不支持地图,

错误:

您使用的浏览器不受 Google Maps JavaScript API 支持。考虑更换您的浏览器。了解更多关闭

我想从网络浏览器控件打开地图,但不是用 ie,我想用谷歌浏览器显示以消除该错误,

我的系统有很多管理权限,但我无法使用注册表

有什么办法可以做到这一点吗?

小智 5

VS默认浏览器控件使用IE。Chrome 浏览器应该使用 cefsharp。首先包含库并像这样初始化......

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();
        }
    }
Run Code Online (Sandbox Code Playgroud)

欲了解更多信息,请参阅下面的链接... https://github.com/cefsharp/CefSharp https://github.com/cefsharp/CefSharp/wiki/Quick-Start