WebBrowser组件未显示CSS 3

我正在构建一个需要WebBrowser组件的软件。 不幸的是,它不会正确显示我的页面。

我的内容使用这种CSS样式:

.content_mid{ background-image:url(http://img.awesome-o.net/Content_Mid.png); background-size: 100% 100%; vertical-align:text-top; padding-left: 40px; padding-right:20px; min-height:400px; } 

由于我已经发现WebBrowser组件使用已安装的interwebs explorer版本,因此我检查了Internet Explorer上的html,并且它显示完美。

在这里你看到它在IE上显示的内容:

在此处输入图像描述

以下是它在webbrowser组件上的显示方式:

在此处输入图像描述

所以,我检查了浏览器版本:

 Debug.WriteLine("WebBrowser version: " + webBrowser1.Version); output: WebBrowser version: 9.0.8112.16443 

我想这应该没问题。

本页介绍如何强制浏览器控件使用特定的呈现模式。

您也可以尝试此doctype

  

和/或head元素中的元元素

  

仅供进一步参考需要此项的其他人:

首先:感谢Boo和Lex Li帮助我找到问题的答案。

您必须将某个注册表设置为正确的值:

32位和64位应用程序有两组不同的键。

32位:

 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION Value Key: yourapplication.exe 

64位:

 HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION Value Key: yourapplication.exe 

将此键设置为的值(取自此处的MSDN)为十进制值:

 9999 (0x270F) Internet Explorer 9. Webpages are displayed in IE9 Standards mode, regardless of the !DOCTYPE directive. 9000 (0x2328) Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode. 8888 (0x22B8) Webpages are displayed in IE8 Standards mode, regardless of the !DOCTYPE directive. 8000 (0x1F40) Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode. 7000 (0x1B58) Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode. 

即使是强硬的MSDn声称9000是自动分配的值。 显然,这根本不是真的。

您可以在下面找到如何将这些密钥添加到注册表的代码。 请不要在调试时应用程序具有不同的进程名称。

 RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION", true); if (key != null) { key.SetValue("YourApplicationName.exe", 9000, RegistryValueKind.DWord); } key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION", true); if (key != null) { key.SetValue("YourApplicationName.exe", 9000, RegistryValueKind.DWord); } 

所以,谢谢大家和好运

编辑:应关闭用户帐户控制以使此代码有效。

您还可以向IIS应用程序添加响应标头,调用X-UA兼容,其值为IE = Edge。 我倾向于将它添加到我的web.config中