【问题标题】:web browser control in winform with google chrome c#带有谷歌浏览器c#的winform中的网络浏览器控件
【发布时间】:2018-03-17 21:54:39
【问题描述】:
大家好,我正在创建一个 winform 应用程序,我在其中向所有用户显示地图,但问题是 Web 浏览器控件将 ie7 作为默认浏览器,并且该特定浏览器不支持地图,
错误:
您使用的浏览器不受 Google 地图支持
JavaScript API。考虑更换浏览器。了解详情关闭
我想从网络浏览器控件打开地图,但不是用 ie,我想用 google chrome 显示以摆脱该错误,
我的系统中有很多管理权限,但我无法使用注册表
有什么办法吗?
【问题讨论】:
标签:
c#
winforms
google-maps
google-chrome
【解决方案1】:
浏览器组件使用 Internet Explorer 作为引擎,因此如果您想要另一个浏览器,您必须找到一个组件。
CefSharp 使用铬作为引擎。
【解决方案2】:
VS默认浏览器控件使用IE。您应该将 cefsharp 用于 chrome 浏览器。
首先包含库并像这样初始化......
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();
}
}
欲了解更多信息,请参阅下面的链接...
https://github.com/cefsharp/CefSharp
https://github.com/cefsharp/CefSharp/wiki/Quick-Start