2012-04-19 25 views
6

我正在構建一個需要WebBrowser組件的軟件。 不幸的是,它不會正確顯示我的頁面。WebBrowser組件不顯示CSS 3

我的內容使用這個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資源管理器的安裝版本,我查了HTML在Internet Explorer,它完美展現。

這裏你可以看到它顯示了IE:

enter image description here

,這裏是它如何顯示網頁瀏覽器組件上:

enter image description here

所以,我檢查瀏覽器的版本:

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

所以我應該沒問題。

+0

請不要用 「C#」 和這樣的前綴您的圖書。這就是標籤的用途。 – 2012-04-21 01:14:45

+0

好吧,對不起,第一個問題 – RoXaS 2012-04-21 10:22:30

回答

9

剛:

首先全部: 感謝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); 
     } 

所以感謝所有的好運

編輯:用戶帳戶控制應該關閉,以使此代碼工作。

11

This page描述瞭如何強制瀏覽器控件使用特定的渲染模式。

你也可以試試這個DOCTYPE

<!DOCTYPE html> 

和/或磁頭組件進一步參考其他人需要這個這個meta元素

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
+0

謝謝你的回答,只是我沒有得到的一件事。 「Internet Explorer 9的默認值是9000.」 「說明:\t Internet Explorer 9.包含基於標準!​​DOCTYPE指令的網頁以IE9模式顯示。」 這對我來說似乎是正確的價值,還是你有不同的看法? – RoXaS 2012-04-20 16:17:30

+0

您的網頁是否定義了文檔類型? – 2012-04-20 18:05:38

+0

是的確如此: <!DOCTYPE html PUBLIC「 - // W3C // DTD XHTML 1.0 Transitional // EN」「http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd」 > – RoXaS 2012-04-20 18:07:52

0

您還可以向IIS應用程序添加一個響應標題,該標題被稱爲X-UA兼容值,其值爲IE = Edge。我傾向於將它添加到我的web.config

+0

感謝您的答案,但我擔心這是一個Windows窗體應用程序的關注。沒有web.config。 – RoXaS 2013-12-03 21:30:41